<!doctype html>



  


<html class="theme-next muse use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  
    
      
    

    
  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Microsoft YaHei:300,300italic,400,400italic,700,700italic|consolas:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="js,事件," />








  <link rel="shortcut icon" type="image/x-icon" href="http://ofy7k3v4s.bkt.clouddn.com/mylogo.png?v=5.0.2" />






<meta name="description" content="JavaScript &amp;#x4E0E; HTML &amp;#x4E4B;&amp;#x95F4;&amp;#x7684;&amp;#x4EA4;&amp;#x4E92;&amp;#x662F;&amp;#x901A;&amp;#x8FC7; &amp;#x4E8B;&amp;#x4EF6; &amp;#x5B9E;&amp;#x73B0;&amp;#x7684;&amp;#x3002;&amp;#x4E8B;&amp;#x4EF6;&amp;#x4E09;&amp;#x8981;&amp;#x7D20;: &amp;#x4E8B;&amp;#x4EF6;&amp;#x">
<meta property="og:type" content="article">
<meta property="og:title" content="js 的事件">
<meta property="og:url" content="https://hongqinma.github.io/2014/10/14/18-js-的事件/index.html">
<meta property="og:site_name" content="HongqinMa' Blog">
<meta property="og:description" content="JavaScript &amp;#x4E0E; HTML &amp;#x4E4B;&amp;#x95F4;&amp;#x7684;&amp;#x4EA4;&amp;#x4E92;&amp;#x662F;&amp;#x901A;&amp;#x8FC7; &amp;#x4E8B;&amp;#x4EF6; &amp;#x5B9E;&amp;#x73B0;&amp;#x7684;&amp;#x3002;&amp;#x4E8B;&amp;#x4EF6;&amp;#x4E09;&amp;#x8981;&amp;#x7D20;: &amp;#x4E8B;&amp;#x4EF6;&amp;#x">
<meta property="og:updated_time" content="2016-11-19T02:33:20.585Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="js 的事件">
<meta name="twitter:description" content="JavaScript &amp;#x4E0E; HTML &amp;#x4E4B;&amp;#x95F4;&amp;#x7684;&amp;#x4EA4;&amp;#x4E92;&amp;#x662F;&amp;#x901A;&amp;#x8FC7; &amp;#x4E8B;&amp;#x4EF6; &amp;#x5B9E;&amp;#x73B0;&amp;#x7684;&amp;#x3002;&amp;#x4E8B;&amp;#x4EF6;&amp;#x4E09;&amp;#x8981;&amp;#x7D20;: &amp;#x4E8B;&amp;#x4EF6;&amp;#x">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '6347850919329138000',
      author: 'Hiraku'
    }
  };
</script>




  <link rel="canonical" href="https://hongqinma.github.io/2014/10/14/18-js-的事件/"/>


  <title> js 的事件 | HongqinMa' Blog </title>
</head>

<body itemscope itemtype="//schema.org/WebPage" lang="en">

  



  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?10010323";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta custom-logo">
  
    <div class="site-meta-headline">
      <a>
        <img class="custom-logo-image" src="http://ofy7k3v4s.bkt.clouddn.com/photo.jpg"
             alt="HongqinMa' Blog"/>
      </a>
    </div>
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">HongqinMa' Blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">Spell at all costs， to rush you in the future。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            About
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="//schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                js 的事件
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2014-10-14T20:49:24+08:00" content="2014-10-14">
              2014-10-14
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/JavaScript/" itemprop="url" rel="index">
                    <span itemprop="name">JavaScript</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2014/10/14/18-js-的事件/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2014/10/14/18-js-的事件/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          

          
              &nbsp; | &nbsp;
              <span class="page-pv"><i class="fa fa-file-o"></i>
              <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
              </span>
          

          
            <span id="busuanzi_container_page_pv">  <span id="busuanzi_value_page_pv"></span> Views</span>
          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>JavaScript &#x4E0E; HTML &#x4E4B;&#x95F4;&#x7684;&#x4EA4;&#x4E92;&#x662F;&#x901A;&#x8FC7; <strong>&#x4E8B;&#x4EF6;</strong> &#x5B9E;&#x73B0;&#x7684;&#x3002;&#x4E8B;&#x4EF6;&#x4E09;&#x8981;&#x7D20;: &#x4E8B;&#x4EF6;&#x6E90;.&#x4E8B;&#x4EF6; = function(){ &#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F; }&#xFF1B;&#x7B49;&#x4EF7;&#x4E8E; &lt;&#x6807;&#x7B7E; &#x4E8B;&#x4EF6;= &#x201C;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x201D;&gt;&#x3002;</p>
<p>&#x4E8B;&#x4EF6;&#x5C31;&#x662F;&#x6587;&#x6863;&#x6216;&#x6D4F;&#x89C8;&#x5668;&#x7A97;&#x53E3;&#x4E2D;&#x53D1;&#x751F;&#x7684;&#x4E00;&#x4E9B;&#x7279;&#x5B9A;&#x4EA4;&#x4E92;&#x77AC;&#x95F4;&#x3002;&#x5305;&#x62EC;&#x4E8B;&#x4EF6;&#x7C7B;&#x578B;&#x3001;&#x4E8B;&#x4EF6;&#x76EE;&#x6807;&#x3001;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x3001;&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x4E8B;&#x4EF6;&#x7C7B;&#x578B;&#x662F;&#x7528;&#x8FC7;&#x7528;&#x6765;&#x8BF4;&#x660E;&#x53D1;&#x751F;&#x4EC0;&#x4E48;&#x7C7B;&#x578B;&#x4E8B;&#x4EF6;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x3002;</p>
<p>&#x4E8B;&#x4EF6;&#x76EE;&#x6807;&#x662F;&#x53D1;&#x751F;&#x7684;&#x4E8B;&#x4EF6;&#x6216;&#x4E0E;&#x4E4B;&#x76F8;&#x5173;&#x7684;&#x5BF9;&#x8C61;&#x3002;&#x5982; window&#x3001;Document&#x3001;Element &#x5BF9;&#x8C61;&#x3002;&#x4EE5;&#x53CA;&#x7531; XMLHTTPRequest &#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x6216;&#x4E8B;&#x4EF6;&#x76D1;&#x542C;&#x7A0B;&#x5E8F;&#x662F;&#x5904;&#x7406;&#x6216;&#x54CD;&#x5E94;&#x4E8B;&#x4EF6;&#x7684;&#x51FD;&#x6570;&#x3002;</p>
<p>&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;&#x662F;&#x4E0E;&#x7279;&#x5B9A;&#x4E8B;&#x4EF6;&#x76F8;&#x5173;&#x4E14;&#x5305;&#x542B;&#x6709;&#x5173;&#x8BE5;&#x4E8B;&#x4EF6;&#x7684;&#x8BE6;&#x7EC6;&#x4FE1;&#x606F;&#x7684;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x4E8B;&#x4EF6;&#x4F20;&#x64AD;&#x662F;&#x6D4F;&#x89C8;&#x5668;&#x51B3;&#x5B9A;&#x54EA;&#x4E2A;&#x5BF9;&#x8C61;&#x89E6;&#x53D1;&#x5176;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x7684;&#x8FC7;&#x7A0B;&#x3002;&#x5F53;&#x6587;&#x6863;&#x5143;&#x7D20;&#x4E0A;&#x53D1;&#x751F;&#x67D0;&#x4E2A;&#x7C7B;&#x578B;&#x7684;&#x4E8B;&#x4EF6;&#x65F6;&#xFF0C;&#x5B83;&#x4EEC;&#x4F1A;&#x5728;&#x6587;&#x6863;&#x6811;&#x4E0A;&#x5411;&#x4E0A;&#x5192;&#x6CE1;&#x3002;</p>
<p>&#x4E8B;&#x4EF6;&#x4F20;&#x64AD;&#x7684;&#x53E6;&#x4E00;&#x4E2D;&#x5F62;&#x5F0F;&#x79F0;&#x4E3A;&#x4E8B;&#x4EF6;&#x6355;&#x83B7;&#xFF0C;&#x5728;&#x5BB9;&#x5668;&#x5143;&#x7D20;&#x4E0A;&#x6CE8;&#x518C;&#x7684;&#x7279;&#x5B9A;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x6709;&#x673A;&#x4F1A;&#x5728;&#x4E8B;&#x4EF6;&#x4F20;&#x64AD;&#x5230;&#x771F;&#x5B9E;&#x76EE;&#x6807;&#x4E4B;&#x524D;&#x6355;&#x83B7;&#x3002;</p>
<h2 id="&#x4E8B;&#x4EF6;&#x6D41;"><a href="#&#x4E8B;&#x4EF6;&#x6D41;" class="headerlink" title="&#x4E8B;&#x4EF6;&#x6D41;"></a>&#x4E8B;&#x4EF6;&#x6D41;</h2><p>&#x4E8B;&#x4EF6;&#x6D41;&#x63CF;&#x8FF0;&#x7684;&#x662F;&#x9875;&#x9762;&#x4E2D;&#x63A5;&#x6536;&#x4E8B;&#x4EF6;&#x7684;&#x987A;&#x5E8F;&#x3002;</p>
<h3 id="&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;"><a href="#&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;" class="headerlink" title="&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;"></a>&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;</h3><p>&#x4E8B;&#x4EF6;&#x5F00;&#x59CB;&#x662F;&#x7531;&#x6700;&#x5177;&#x4F53;&#x7684;&#x5143;&#x7D20;&#xFF08;&#x6587;&#x6863;&#x4E2D;&#x5D4C;&#x5957;&#x6700;&#x6DF1;&#x7684;&#x90A3;&#x4E2A;&#x8282;&#x70B9;&#xFF09;&#x63A5;&#x6536;&#xFF0C;&#x7136;&#x540E;&#x9010;&#x7EA7;&#x5411;&#x4E0A;&#x4F20;&#x64AD;&#x5230;&#x8F83;&#x4E3A;&#x4E0D;&#x5177;&#x4F53;&#x7684;&#x8282;&#x70B9;&#x3002;IE&#x3001;FireFox&#x3001;Chrome&#x3001;Safari&#x5C06;&#x4E8B;&#x4EF6;&#x4E00;&#x76F4;&#x5192;&#x6CE1;&#x5230; window &#x4E0A;&#x3002;</p>
<h3 id="&#x4E8B;&#x4EF6;&#x6355;&#x83B7;"><a href="#&#x4E8B;&#x4EF6;&#x6355;&#x83B7;" class="headerlink" title="&#x4E8B;&#x4EF6;&#x6355;&#x83B7;"></a>&#x4E8B;&#x4EF6;&#x6355;&#x83B7;</h3><p>&#x76EE;&#x7684;&#x662F;&#x5728;&#x4E8B;&#x4EF6;&#x5230;&#x8FBE;&#x9884;&#x5B9A;&#x76EE;&#x6807;&#x4E4B;&#x524D;&#x6355;&#x83B7;&#x5B83;&#x3002;&#x4E0D;&#x592A;&#x5177;&#x4F53;&#x7684;&#x8282;&#x70B9;&#x6700;&#x5148;&#x6536;&#x5230;&#x4E8B;&#x4EF6;&#xFF0C;&#x800C;&#x6700;&#x5177;&#x4F53;&#x7684;&#x8282;&#x70B9;&#x5E94;&#x8BE5;&#x6700;&#x540E;&#x6536;&#x5230;&#x4E8B;&#x4EF6;&#x3002;</p>
<h3 id="DOM-&#x4E8B;&#x4EF6;&#x6D41;"><a href="#DOM-&#x4E8B;&#x4EF6;&#x6D41;" class="headerlink" title="DOM &#x4E8B;&#x4EF6;&#x6D41;"></a>DOM &#x4E8B;&#x4EF6;&#x6D41;</h3><p>&#x4E8B;&#x4EF6;&#x6D41;&#x7684;&#x4E09;&#x4E2A;&#x9636;&#x6BB5;&#xFF1A;</p>
<ul>
<li>&#x4E8B;&#x4EF6;&#x6355;&#x83B7;&#x9636;&#x6BB5;</li>
<li>&#x5904;&#x4E8E;&#x76EE;&#x6807;&#x9636;&#x6BB5;</li>
<li>&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;&#x9636;&#x6BB5;</li>
</ul>
<p>&#x5728; DOM &#x4E8B;&#x4EF6;&#x6D41;&#x4E2D;&#xFF0C;&#x5B9E;&#x9645;&#x76EE;&#x6807;&#x5728;&#x6355;&#x83B7;&#x9636;&#x6BB5;&#x4E0D;&#x4F1A;&#x63A5;&#x6536;&#x5230;&#x4E8B;&#x4EF6;&#x3002;&#x4E0B;&#x4E00;&#x4E2A;&#x9636;&#x6BB5;&#x662F;&#x201D;&#x5904;&#x4E8E;&#x76EE;&#x6807;&#x9636;&#x6BB5;&#x201D;&#xFF0C;&#x4E8B;&#x4EF6;&#x5728;&#x76EE;&#x6807;&#x4E0A;&#x53D1;&#x751F;&#xFF0C;&#x5E76;&#x5728;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x4E2D;&#x770B;&#x6210;&#x662F;&#x5192;&#x6CE1;&#x9636;&#x6BB5;&#x7684;&#x4E00;&#x90E8;&#x5206;&#x3002;&#x7136;&#x540E;&#xFF0C;&#x5192;&#x6CE1;&#x9636;&#x6BB5;&#x53D1;&#x751F;&#x3002;</p>
<h2 id="&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;"><a href="#&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;" class="headerlink" title="&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;"></a>&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;</h2><h3 id="HTML-&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;"><a href="#HTML-&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;" class="headerlink" title="HTML &#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;"></a>HTML &#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;button&quot;</span> <span class="attr">name</span>=<span class="string">&quot;butt1&quot;</span> <span class="attr">value</span>=<span class="string">&quot;&#x70B9;&#x6211;&quot;</span> <span class="attr">onclick</span>=<span class="string">&quot;console.log(&apos;&#x6211;&#x88AB;&#x70B9;&#x51FB;&#x4E86;&apos;)&quot;</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;button&quot;</span> <span class="attr">name</span>=<span class="string">&quot;butt2&quot;</span> <span class="attr">value</span>=<span class="string">&quot;&#x70B9;&#x6211;&quot;</span> <span class="attr">onclick</span>=<span class="string">&quot;showMsg()&quot;</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="javascript"></span></div><div class="line">  <span class="function"><span class="keyword">function</span> <span class="title">showMsg</span>(<span class="params"></span>) </span>{</div><div class="line">    <span class="built_in">console</span>.log(<span class="string">&apos;&#x88AB;&#x70B9;&#x4E86;&apos;</span>);</div><div class="line">  }</div><div class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;button&quot;</span> <span class="attr">name</span>=<span class="string">&quot;butt3&quot;</span> <span class="attr">value</span>=<span class="string">&quot;&#x70B9;&#x6211;&quot;</span> <span class="attr">onclick</span>=<span class="string">&quot;console.log(event.type)&quot;</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;button&quot;</span> <span class="attr">name</span>=<span class="string">&quot;butt4&quot;</span> <span class="attr">value</span>=<span class="string">&quot;&#x70B9;&#x6211;&quot;</span> <span class="attr">onclick</span>=<span class="string">&quot;console.log(this.value)&quot;</span>&gt;</span></div></pre></td></tr></table></figure>
<p>event &#x53D8;&#x91CF;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8BBF;&#x95EE;&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;&#x3002;this &#x6307;&#x7684;&#x662F;&#x89E6;&#x53D1;&#x4E8B;&#x4EF6;&#x7684;&#x5F53;&#x524D;&#x5143;&#x7D20;&#x3002;</p>
<p>HTML &#x6307;&#x5B9A;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x7684;&#x7F3A;&#x70B9;&#x662F;&#xFF1A;HTML &#x548C; JavaScript &#x4EE3;&#x7801;&#x7D27;&#x5BC6;&#x8026;&#x5408;&#x3002;</p>
<h3 id="DOM0-&#x7EA7;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;"><a href="#DOM0-&#x7EA7;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;" class="headerlink" title="DOM0 &#x7EA7;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;"></a>DOM0 &#x7EA7;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;</h3><p>&#x5C06;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x8D4B;&#x503C;&#x7ED9;&#x4E00;&#x4E2A;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x5C5E;&#x6027;&#x3002;&#x4F18;&#x70B9;&#xFF1A;&#x7B80;&#x5355;&#x3001;&#x8DE8;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x4F18;&#x52BF;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> btn = <span class="built_in">document</span>.getElementById(<span class="string">&quot;btn&quot;</span>);</div><div class="line">btn.onclick = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</div><div class="line">  <span class="built_in">console</span>.log(<span class="string">&quot;&#x6211;&#x88AB;&#x70B9;&#x51FB;&#x4E86;&quot;</span>);</div><div class="line">}</div></pre></td></tr></table></figure>
<h3 id="DOM2-&#x7EA7;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;"><a href="#DOM2-&#x7EA7;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;" class="headerlink" title="DOM2 &#x7EA7;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;"></a>DOM2 &#x7EA7;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;</h3><p>&#x5B9A;&#x4E49;&#x4E86;&#x4E24;&#x4E2A;&#x6307;&#x5B9A;&#x548C;&#x5220;&#x9664;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x7684;&#x64CD;&#x4F5C;&#xFF1A; addEventListener() &#x548C; removeEventListener()&#xFF1B;&#x63A5;&#x6536; 3 &#x4E2A;&#x53C2;&#x6570;&#xFF1A;</p>
<ul>
<li>&#x8981;&#x5904;&#x7406;&#x7684;&#x4E8B;&#x4EF6;&#x540D;</li>
<li>&#x4F5C;&#x4E3A;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x7684;&#x51FD;&#x6570;</li>
<li>&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#xFF1A;true &#x65F6;&#x8868;&#x793A;&#x5728;&#x6355;&#x83B7;&#x9636;&#x6BB5;&#x8C03;&#x7528;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#xFF0C;false &#x8868;&#x793A;&#x5728;&#x5192;&#x6CE1;&#x9636;&#x6BB5;&#x8C03;&#x7528;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x3002;</li>
</ul>
<h3 id="IE-&#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;"><a href="#IE-&#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;" class="headerlink" title="IE &#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;"></a>IE &#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;</h3><ul>
<li>attachEvent()</li>
<li>detachEvent()</li>
</ul>
<p>&#x5747;&#x63A5;&#x6536;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x540D;&#x79F0;&#x548C;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x51FD;&#x6570;&#x3002;&#x901A;&#x8FC7; attachEvent &#x6DFB;&#x52A0;&#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x90FD;&#x4F1A;&#x88AB;&#x6DFB;&#x52A0;&#x5230;&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;&#x9636;&#x6BB5;&#x3002;</p>
<h3 id="&#x8DE8;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;"><a href="#&#x8DE8;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;" class="headerlink" title="&#x8DE8;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;"></a>&#x8DE8;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;</h3><p>&#x5C01;&#x88C5;&#x4E00;&#x4E2A;&#x517C;&#x5BB9;&#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#xFF0C;&#x53C2;&#x6570;&#x662F;&#xFF1A;&#x8981;&#x64CD;&#x4F5C;&#x7684;&#x5143;&#x7D20;&#x3001;&#x4E8B;&#x4EF6;&#x7C7B;&#x578B;&#x3001;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> EventUtil = {</div><div class="line">  <span class="attr">addHandler</span>: <span class="function"><span class="keyword">function</span>(<span class="params">element, type, handler</span>) </span>{</div><div class="line">    <span class="keyword">if</span> (element.addEventListener) {</div><div class="line">      element.addEventListener(type, handler, <span class="literal">false</span>);</div><div class="line">    } <span class="keyword">else</span> <span class="keyword">if</span> (element.attachEvent) {</div><div class="line">      element.attachEvent(<span class="string">&quot;on&quot;</span> + type, handler);</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      element[<span class="string">&quot;on&quot;</span> + type] = <span class="literal">null</span>;</div><div class="line">    }</div><div class="line">  },</div><div class="line">  <span class="attr">removeHandler</span>: <span class="function"><span class="keyword">function</span>(<span class="params">element, type, handler</span>) </span>{</div><div class="line">    <span class="keyword">if</span> (element.removeListener) {</div><div class="line">      element.removeListener(type, handler, <span class="literal">false</span>);</div><div class="line">    } <span class="keyword">else</span> <span class="keyword">if</span> (element.detachEvent) {</div><div class="line">      element.detachEvent(<span class="string">&quot;on&quot;</span> + type, handler);</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      element[<span class="string">&quot;on&quot;</span> + type] = <span class="literal">null</span>;</div><div class="line">    }</div><div class="line">  }</div><div class="line">}</div></pre></td></tr></table></figure>
<h2 id="&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;"><a href="#&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;" class="headerlink" title="&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;"></a>&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;</h2><p>&#x5728;&#x89E6;&#x53D1; DOM &#x4E0A;&#x7684;&#x67D0;&#x4E2A;&#x4E8B;&#x4EF6;&#x65F6;&#xFF0C;&#x4F1A;&#x4EA7;&#x751F;&#x4E00;&#x4E2A;&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61; event&#xFF0C;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;&#x4E2D;&#x5305;&#x542B;&#x7740;&#x6240;&#x6709;&#x4E0E;&#x4E8B;&#x4EF6;&#x76F8;&#x5173;&#x7684;&#x4FE1;&#x606F;&#x3002;&#x5305;&#x62EC;&#xFF1A;</p>
<ul>
<li>&#x5BFC;&#x81F4;&#x4E8B;&#x4EF6;&#x7684;&#x5143;&#x7D20;</li>
<li>&#x4E8B;&#x4EF6;&#x7C7B;&#x578B;</li>
<li>&#x4E8B;&#x4EF6;&#x76F8;&#x5173;&#x4FE1;&#x606F;</li>
</ul>
<h3 id="DOM-&#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;"><a href="#DOM-&#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;" class="headerlink" title="DOM &#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;"></a>DOM &#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;</h3><p>&#x517C;&#x5BB9; DOM &#x6D4F;&#x89C8;&#x5668;&#x4F1A;&#x5C06;&#x4E00;&#x4E2A; event &#x5BF9;&#x8C61;&#x4F20;&#x5165;&#x5230;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x4E2D;&#x3002;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x62FF;&#x5230; event &#x5BF9;&#x8C61;&#x7684;&#x4FE1;&#x606F;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> btn = <span class="built_in">document</span>.getElementById(<span class="string">&quot;btn&quot;</span>);</div><div class="line">btn.onclick = <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>{</div><div class="line">  <span class="built_in">console</span>.log(event.type);   <span class="comment">// &quot;click&quot;</span></div><div class="line">}</div><div class="line">btn.addEventlistener(<span class="string">&quot;click&quot;</span>, <span class="function"><span class="keyword">function</span>(<span class="params">event</span>)</span>{</div><div class="line">  <span class="built_in">console</span>.log(event.type);   <span class="comment">// &quot;click&quot;</span></div><div class="line">}, <span class="literal">false</span>);</div></pre></td></tr></table></figure>
<p>&#x5728;&#x901A;&#x8FC7; HTML &#x7279;&#x6027;&#x6307;&#x5B9A;&#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#xFF0C;&#x53D8;&#x91CF; event &#x4FDD;&#x5B58;&#x7740; event &#x5BF9;&#x8C61;&#x3002;</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;button&quot;</span> <span class="attr">name</span>=<span class="string">&quot;btn&quot;</span> <span class="attr">value</span>=<span class="string">&quot;&#x70B9;&#x6211;&quot;</span> <span class="attr">onclick</span>=<span class="string">&quot;console.log(event.type)&quot;</span> /&gt;</span></div></pre></td></tr></table></figure>
<p>event &#x5BF9;&#x8C61;&#x5305;&#x542B;&#x4E0E;&#x521B;&#x5EFA;&#x5B83;&#x7684;&#x7279;&#x5B9A;&#x4E8B;&#x4EF6;&#x6709;&#x5173;&#x7684;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x3002;&#x89E6;&#x53D1;&#x7684;&#x4E8B;&#x4EF6;&#x4E0D;&#x540C;&#xFF0C;&#x53EF;&#x7528;&#x7684;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x4E5F;&#x4E0D;&#x4E00;&#x6837;&#x3002;&#x4F46;&#x6240;&#x6709;&#x4E8B;&#x4EF6;&#x90FD;&#x4F1A;&#x6709;&#x4E0B;&#x8868;&#x4E2D;&#x5217;&#x51FA;&#x7684;&#x65B9;&#x6CD5;&#x3002;</p>
<p>| &#x5C5E;&#x6027;/&#x65B9;&#x6CD5;                  | &#x7C7B;&#x578B;         | &#x8BFB;/&#x5199; | &#x8BF4;&#x660E;                                                                      |<br>| bubbles                    | Boolean      | &#x53EA;&#x8BFB;  | &#x8868;&#x660E;&#x662F;&#x5426;&#x5192;&#x6CE1;                                                              |<br>| cancelable                 | Boolean      | &#x53EA;&#x8BFB;  | &#x662F;&#x5426;&#x53EF;&#x4EE5;&#x53D6;&#x6D88;&#x4E8B;&#x4EF6;&#x7684;&#x9ED8;&#x8BA4;&#x884C;&#x4E3A;                                                |<br>| currentTarget              | Element      | &#x53EA;&#x8BFB;  | &#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x5F53;&#x524D;&#x6B63;&#x5728;&#x5904;&#x7406;&#x4E8B;&#x4EF6;&#x7684;&#x90A3;&#x4E2A;&#x5143;&#x7D20;                                    |<br>| defaultPrevented           | Boolean      | &#x53EA;&#x8BFB;  | true &#x65F6;&#x8868;&#x793A;&#x8C03;&#x7528;&#x4E86; perventDefault()                                        |<br>| detail                     | Integer      | &#x53EA;&#x8BFB;  | &#x4E8B;&#x4EF6;&#x76F8;&#x5173;&#x7684;&#x7EC6;&#x8282;&#x4FE1;&#x606F;                                                        |<br>| eventPhase                 | Integer      | &#x53EA;&#x8BFB;  | &#x8C03;&#x7528;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x7684;&#x9636;&#x6BB5;&#xFF1A;1&#x6355;&#x83B7; 2&#x5904;&#x4E8E;&#x76EE;&#x6807; 3&#x5192;&#x6CE1;                             |<br>| perventDefault()           | Function     | &#x53EA;&#x8BFB;  | &#x53D6;&#x6D88;&#x4E8B;&#x4EF6;&#x9ED8;&#x8BA4;&#x884C;&#x4E3A;&#xFF0C;&#x5982;&#x679C;candelable&#x662F;true&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;                    |<br>| stopImmediatePropagation() | Function     | &#x53EA;&#x8BFB;  | &#x53D6;&#x6D88;&#x4E8B;&#x4EF6;&#x7684;&#x8FDB;&#x4E00;&#x6B65;&#x6355;&#x83B7;&#x6216;&#x5192;&#x6CE1;&#xFF0C;&#x540C;&#x65F6;&#x963B;&#x6B62;&#x4EFB;&#x4F55;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x8C03;&#x7528;                  |<br>| stopPropagation()          | Function     | &#x53EA;&#x8BFB;  | &#x53D6;&#x6D88;&#x4E8B;&#x4EF6;&#x7684;&#x8FDB;&#x4E00;&#x6B65;&#x6355;&#x83B7;&#x6216;&#x5192;&#x6CE1;&#xFF0C;&#x5982;&#x679C; bubbles &#x4E3A; true&#xFF0C;&#x5219;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;      |<br>| target                     | Element      | &#x53EA;&#x8BFB;  | &#x4E8B;&#x4EF6;&#x76EE;&#x6807;                                                                  |<br>| trusted                    | Boolean      | &#x53EA;&#x8BFB;  | &#x4E3A; true &#x65F6;&#x8868;&#x793A;&#x6D4F;&#x89C8;&#x5668;&#x751F;&#x6210;&#x7684;&#xFF0C;&#x4E3A; false &#x65F6;&#x8868;&#x793A;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x901A;&#x8FC7; javascript &#x521B;&#x5EFA;&#x7684; |<br>| type                       | String       | &#x53EA;&#x8BFB;  | &#x88AB;&#x89E6;&#x53D1;&#x7684;&#x4E8B;&#x4EF6;&#x7C7B;&#x578B;                                                          |<br>| view                       | AbstractView | &#x53EA;&#x8BFB;  | &#x4E0E;&#x4E8B;&#x4EF6;&#x76F8;&#x5173;&#x8054;&#x7684;&#x62BD;&#x8C61;&#x89C6;&#x56FE;&#x3002;&#x7B49;&#x540C;&#x4E8E;&#x53D1;&#x751F;&#x4E8B;&#x4EF6;&#x7684; window &#x5BF9;&#x8C61;                      |</p>
<p>&#x5728;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x7684;&#x5185;&#x90E8;&#xFF0C;this &#x59CB;&#x7EC8;&#x7B49;&#x4E8E; currentTarget &#x7684;&#x503C;&#xFF0C;&#x800C; target &#x53EA;&#x5305;&#x542B;&#x4E8B;&#x4EF6;&#x7684;&#x5B9E;&#x9645;&#x76EE;&#x6807;&#x3002;&#x5982;&#x679C;&#x65F6;&#x95F4;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x6307;&#x5B9A;&#x7ED9;&#x4E86;&#x76EE;&#x6807;&#x5143;&#x7D20;&#x3002;&#x5219;&#x8FD9;&#x4E09;&#x4E2A;&#x7684;&#x503C;&#x76F8;&#x7B49;&#x3002;</p>
<p>stopPropagation() &#x65B9;&#x6CD5;&#x7528;&#x4E8E;&#x7ACB;&#x5373;&#x505C;&#x6B62;&#x4E8B;&#x4EF6;&#x5728; DOM &#x5C42;&#x6B21;&#x4E2D;&#x7684;&#x4F20;&#x64AD;&#xFF0C;&#x5373;&#x53D6;&#x6D88;&#x8FDB;&#x4E00;&#x6B65;&#x7684;&#x4E8B;&#x4EF6;&#x6355;&#x83B7;&#x6216;&#x5192;&#x6CE1;&#x3002;</p>
<h3 id="IE-&#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;"><a href="#IE-&#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;" class="headerlink" title="IE &#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;"></a>IE &#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;</h3><p>event &#x5BF9;&#x8C61;&#x4F5C;&#x4E3A; window &#x5BF9;&#x8C61;&#x7684;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x5B58;&#x5728;&#x3002;</p>
<p>| &#x5C5E;&#x6027;/&#x65B9;&#x6CD5;   | &#x7C7B;&#x578B;    | &#x8BFB;/&#x5199; | &#x8BF4;&#x660E;                                           |<br>| cancelables | Boolean | &#x8BFB;/&#x5199; | &#x9ED8;&#x8BA4;&#x503C;&#x662F; false&#xFF0C;&#x8BBE;&#x7F6E;&#x4E3A; true &#x5C31;&#x53EF;&#x4EE5;&#x53D6;&#x6D88;&#x4E8B;&#x4EF6;&#x5192;&#x6CE1; |<br>| returnValue | Boolean | &#x8BFB;/&#x5199; | &#x9ED8;&#x8BA4; true&#xFF0C;&#x8BBE;&#x4E3A; false &#x53EF;&#x4EE5;&#x53D6;&#x6D88;&#x4E8B;&#x4EF6;&#x7684;&#x9ED8;&#x8BA4;&#x884C;&#x4E3A;   |<br>| srcElement  | Element | &#x53EA;&#x8BFB;  | &#x4E8B;&#x4EF6;&#x7684;&#x76EE;&#x6807;                                     |<br>| type        | String  | &#x53EA;&#x8BFB;  | &#x88AB;&#x89E6;&#x53D1;&#x7684;&#x4E8B;&#x4EF6;&#x7C7B;&#x578B;                                               |</p>
<h3 id="&#x8DE8;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;"><a href="#&#x8DE8;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;" class="headerlink" title="&#x8DE8;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;"></a>&#x8DE8;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x4E8B;&#x4EF6;&#x5BF9;&#x8C61;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> EventUtil = {</div><div class="line">  <span class="attr">addHandler</span>: <span class="function"><span class="keyword">function</span>(<span class="params">element, type, handler</span>) </span>{</div><div class="line">    <span class="keyword">if</span> (element.addEventListener) {</div><div class="line">      element.addEventListener(type, handler, <span class="literal">false</span>);</div><div class="line">    } <span class="keyword">else</span> <span class="keyword">if</span> (element.attachEvent) {</div><div class="line">      element.attachEvent(<span class="string">&quot;on&quot;</span> + type, handler);</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      element[<span class="string">&quot;on&quot;</span> + type] = <span class="literal">null</span>;</div><div class="line">    }</div><div class="line">  },</div><div class="line">  <span class="attr">removeHandler</span>: <span class="function"><span class="keyword">function</span>(<span class="params">element, type, handler</span>) </span>{</div><div class="line">    <span class="keyword">if</span> (element.removeListener) {</div><div class="line">      element.removeListener(type, handler, <span class="literal">false</span>);</div><div class="line">    } <span class="keyword">else</span> <span class="keyword">if</span> (element.detachEvent) {</div><div class="line">      element.detachEvent(<span class="string">&quot;on&quot;</span> + type, handler);</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      element[<span class="string">&quot;on&quot;</span> + type] = <span class="literal">null</span>;</div><div class="line">    }</div><div class="line">  },</div><div class="line">  <span class="attr">getEvent</span>: <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>{</div><div class="line">    <span class="keyword">return</span> event ? event : <span class="built_in">window</span>.event;</div><div class="line">  },</div><div class="line">  <span class="attr">getTarget</span>: <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>{</div><div class="line">    <span class="keyword">return</span> event.target || event.srcElement;</div><div class="line">  },</div><div class="line">  <span class="attr">preventDefault</span>: <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>{</div><div class="line">    <span class="keyword">if</span> (event.preventDefault) {</div><div class="line">      event.preventDefault;</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      event.returnValue = <span class="literal">false</span>;</div><div class="line">    }</div><div class="line">  },</div><div class="line">  <span class="attr">stopPropagation</span>: <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>{</div><div class="line">    <span class="keyword">if</span> (event.stopPropagation) {</div><div class="line">      event.stopPropagation;</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      event.cancelBubble = <span class="literal">true</span>;</div><div class="line">    }</div><div class="line">  }</div><div class="line">}</div></pre></td></tr></table></figure>
<h2 id="&#x4E8B;&#x4EF6;&#x7C7B;&#x578B;"><a href="#&#x4E8B;&#x4EF6;&#x7C7B;&#x578B;" class="headerlink" title="&#x4E8B;&#x4EF6;&#x7C7B;&#x578B;"></a>&#x4E8B;&#x4EF6;&#x7C7B;&#x578B;</h2><ul>
<li>UI &#x4E8B;&#x4EF6;&#xFF1A;&#x7528;&#x6237;&#x4E0E;&#x9875;&#x9762;&#x4E0A;&#x7684;&#x5143;&#x7D20;&#x4EA4;&#x4E92;&#x65F6;&#x89E6;&#x53D1;&#xFF1B;</li>
<li>&#x7126;&#x70B9;&#x4E8B;&#x4EF6;&#xFF1A;&#x5143;&#x7D20;&#x83B7;&#x53D6;&#x7126;&#x70B9;&#x6216;&#x5931;&#x53BB;&#x7126;&#x70B9;&#x65F6;&#x89E6;&#x53D1;</li>
<li>&#x9F20;&#x6807;&#x4E8B;&#x4EF6;</li>
<li>&#x6EDA;&#x8F6E;&#x4E8B;&#x4EF6;</li>
<li>&#x6587;&#x672C;&#x4E8B;&#x4EF6;</li>
<li>&#x952E;&#x76D8;&#x4E8B;&#x4EF6;</li>
<li>&#x5408;&#x6210;&#x4E8B;&#x4EF6;</li>
<li>&#x53D8;&#x52A8;&#x4E8B;&#x4EF6;&#xFF1A;&#x5E95;&#x5C42; DOM &#x7ED3;&#x6784;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x65F6;&#x89E6;&#x53D1;</li>
</ul>
<h3 id="UI-&#x4E8B;&#x4EF6;"><a href="#UI-&#x4E8B;&#x4EF6;" class="headerlink" title="UI &#x4E8B;&#x4EF6;"></a>UI &#x4E8B;&#x4EF6;</h3><ul>
<li>DOMActive &#x5DF2;&#x5E9F;&#x5F03;</li>
<li>load: &#x9875;&#x9762;&#x5B8C;&#x5168;&#x52A0;&#x8F7D;&#x540E;&#x5728; window &#x4E0A;&#x89E6;&#x53D1;</li>
<li>unload&#xFF1A;&#x9875;&#x9762;&#x5378;&#x8F7D;&#x540E;&#x5728; window &#x4E0A;&#x89E6;&#x53D1;</li>
<li>abort&#xFF1A;&#x5728;&#x7528;&#x6237;&#x505C;&#x6B62;&#x4E0B;&#x8F7D;&#x8FC7;&#x7A0B;&#x65F6;&#xFF0C;&#x5982;&#x679C;&#x5D4C;&#x5165;&#x7684;&#x5143;&#x7D20;&#x6CA1;&#x6709;&#x52A0;&#x8F7D;&#x5B8C;&#xFF0C;&#x5219;&#x5728;&#x76EE;&#x6807;&#x5143;&#x7D20;&#x4E0A;&#x9762;&#x89E6;&#x53D1;</li>
<li>select&#xFF1A;&#x5F53;&#x7528;&#x6237;&#x9009;&#x62E9;&#x6587;&#x672C;&#x6846;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x65F6;&#x89E6;&#x53D1;</li>
<li>resize&#xFF1A;&#x5F53;&#x7A97;&#x53E3;&#x6216;&#x6846;&#x67B6;&#x7684;&#x5927;&#x5C0F;&#x53D8;&#x5316;&#x65F6;&#x89E6;&#x53D1;</li>
<li>scroll&#xFF1A;&#x5F53;&#x7528;&#x6237;&#x6EDA;&#x52A8;&#x5E26;&#x6EDA;&#x52A8;&#x6761;&#x7684;&#x5143;&#x7D20;&#x4E2D;&#x7684;&#x5185;&#x5BB9;&#x65F6;&#x5728;&#x8BE5;&#x5143;&#x7D20;&#x4E0A;&#x89E6;&#x53D1;&#x3002;</li>
</ul>
<h3 id="&#x7126;&#x70B9;&#x4E8B;&#x4EF6;"><a href="#&#x7126;&#x70B9;&#x4E8B;&#x4EF6;" class="headerlink" title="&#x7126;&#x70B9;&#x4E8B;&#x4EF6;"></a>&#x7126;&#x70B9;&#x4E8B;&#x4EF6;</h3><ul>
<li>blur&#xFF1A;&#x5143;&#x7D20;&#x5931;&#x53BB;&#x7126;&#x70B9;&#x65F6;&#x89E6;&#x53D1;&#xFF1B;&#x8FD9;&#x4E2A;&#x4E8B;&#x4EF6;&#x4E0D;&#x4F1A;&#x5192;&#x6CE1;&#x3002;</li>
<li>DOMFocusIn&#xFF1A;&#x5728;&#x5143;&#x7D20;&#x83B7;&#x53D6;&#x7126;&#x70B9;&#x65F6;&#x89E6;&#x53D1;&#x3002;&#x4E0E; HTML &#x4E8B;&#x4EF6;&#x7684; focus &#x7B49;&#x4EF7;&#x3002;&#x53EA;&#x6709; Opera &#x652F;&#x6301;&#x3002;DOM3 &#x7EA7;&#x5DF2;&#x5E9F;&#x5F03;&#xFF0C;&#x9009;&#x62E9;&#x4E86; focusin&#x3002;</li>
<li>DOMFocusOut&#xFF1A;&#x5728;&#x5143;&#x7D20;&#x5931;&#x53BB;&#x7126;&#x70B9;&#x65F6;&#x89E6;&#x53D1;&#x3002;DOM3 &#x7EA7;&#x5DF2;&#x5E9F;&#x5F03;&#xFF0C;&#x9009;&#x62E9;&#x4E86; focusout&#x3002;</li>
<li>focus: &#x83B7;&#x53D6;&#x7126;&#x70B9;&#x65F6;&#x89E6;&#x53D1;&#x3002; </li>
<li>focusin&#xFF1A;&#x5B83;&#x5192;&#x6CE1;&#xFF0C;&#x548C; HTML &#x7684; focus &#x4E8B;&#x4EF6;&#x7B49;&#x4EF7;&#x3002;</li>
<li>focusout&#xFF1A;&#x5B83;&#x5192;&#x6CE1;&#xFF0C;&#x662F; HTML &#x7684; blur &#x4E8B;&#x4EF6;&#x7684;&#x901A;&#x7528;&#x7248;&#x672C;&#x3002;</li>
</ul>
<h3 id="&#x9F20;&#x6807;&#x4E0E;&#x6EDA;&#x8F6E;&#x4E8B;&#x4EF6;"><a href="#&#x9F20;&#x6807;&#x4E0E;&#x6EDA;&#x8F6E;&#x4E8B;&#x4EF6;" class="headerlink" title="&#x9F20;&#x6807;&#x4E0E;&#x6EDA;&#x8F6E;&#x4E8B;&#x4EF6;"></a>&#x9F20;&#x6807;&#x4E0E;&#x6EDA;&#x8F6E;&#x4E8B;&#x4EF6;</h3><ul>
<li>click&#xFF1A;&#x7528;&#x6237;&#x5355;&#x51FB;&#x9F20;&#x6807;&#x6309;&#x94AE;&#xFF08;&#x4E00;&#x822C;&#x662F;&#x5DE6;&#x952E;&#xFF09;&#x6216;&#x8005;&#x6309;&#x4E0B; Enter &#x952E;&#x65F6;&#x89E6;&#x53D1;&#x3002;</li>
<li>dbclick&#xFF1A;&#x53CC;&#x51FB;&#x9F20;&#x6807;&#x89E6;&#x53D1;&#x3002;&#x4E0D;&#x80FD;&#x901A;&#x8FC7;&#x952E;&#x76D8;&#x89E6;&#x53D1;&#x8FD9;&#x4E2A;&#x4E8B;&#x4EF6;&#x3002;</li>
<li>mousedown&#xFF1A;&#x6309;&#x4E0B;&#x4E86;&#x9F20;&#x6807;&#x4EFB;&#x610F;&#x952E;&#x89E6;&#x53D1;&#x3002;&#x4E0D;&#x80FD;&#x901A;&#x8FC7;&#x952E;&#x76D8;&#x89E6;&#x53D1;&#x8FD9;&#x4E2A;&#x4E8B;&#x4EF6;&#x3002;</li>
<li>mouseenter&#xFF1A;&#x5728;&#x9F20;&#x6807;&#x5149;&#x6807;&#x4ECE;&#x5143;&#x7D20;&#x5916;&#x90E8;&#x9996;&#x6B21;&#x79FB;&#x52A8;&#x5230;&#x5143;&#x7D20;&#x8303;&#x56F4;&#x4E4B;&#x5185;&#x65F6;&#x89E6;&#x53D1;&#x3002;&#x8FD9;&#x4E2A;&#x4E8B;&#x4EF6;&#x4E0D;&#x5192;&#x6CE1;&#xFF0C;&#x800C;&#x4E14;&#x5728;&#x5149;&#x6807;&#x79FB;&#x52A8;&#x5230;&#x540E;&#x4EE3;&#x5143;&#x7D20;&#x4E0A;&#x4E0D;&#x4F1A;&#x89E6;&#x53D1;&#x3002;</li>
<li>mouseleave&#xFF1A;&#x5728;&#x4F4D;&#x4E8E;&#x5143;&#x7D20;&#x4E0A;&#x65B9;&#x7684;&#x9F20;&#x6807;&#x5149;&#x6807;&#x79FB;&#x52A8;&#x5230;&#x5143;&#x7D20;&#x8303;&#x56F4;&#x4E4B;&#x5916;&#x65F6;&#x89E6;&#x53D1;&#x3002;&#x8FD9;&#x4E2A;&#x4E8B;&#x4EF6;&#x4E0D;&#x5192;&#x6CE1;&#xFF0C;&#x800C;&#x4E14;&#x5728;&#x5149;&#x6807;&#x79FB;&#x52A8;&#x5230;&#x540E;&#x4EE3;&#x5143;&#x7D20;&#x4E0A;&#x4E0D;&#x4F1A;&#x89E6;&#x53D1;&#x3002;<ul>
<li>mouseenter &#x548C; mouseleave &#x662F;&#x4E00;&#x5BF9;&#xFF0C;IE&#x3001;FireFox 9+ &#x548C; Opera &#x652F;&#x6301;&#x8FD9;&#x4E2A;&#x4E8B;&#x4EF6;&#x3002;</li>
</ul>
</li>
<li>mousemove&#xFF1A;&#x9F20;&#x6807;&#x6307;&#x9488;&#x5728;&#x5143;&#x7D20;&#x5185;&#x90E8;&#x79FB;&#x52A8;&#x65F6;&#x91CD;&#x590D;&#x89E6;&#x53D1;&#x3002;</li>
<li>mouseout&#xFF1A;&#x5728;&#x9F20;&#x6807;&#x6307;&#x9488;&#x4F4D;&#x4E8E;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x4E0A;&#xFF0C;&#x7136;&#x540E;&#x7528;&#x6237;&#x5C06;&#x5176;&#x79FB;&#x5165;&#x53E6;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x65F6;&#x89E6;&#x53D1;&#x3002;</li>
<li>mouseover&#xFF1A;&#x5728;&#x9F20;&#x6807;&#x6307;&#x9488;&#x4F4D;&#x4E8E;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x5916;&#x90E8;&#xFF0C;&#x7136;&#x540E;&#x7528;&#x6237;&#x5C06;&#x5176;&#x9996;&#x6B21;&#x79FB;&#x5165;&#x53E6;&#x4E00;&#x5143;&#x7D20;&#x8FB9;&#x754C;&#x4E4B;&#x5185;&#x65F6;&#x89E6;&#x53D1;</li>
<li>mouseup&#xFF1A;&#x9F20;&#x6807;&#x62AC;&#x8D77;&#x65F6;&#x89E6;&#x53D1;&#x3002;</li>
</ul>
<h4 id="&#x6EDA;&#x8F6E;&#x4E8B;&#x4EF6;"><a href="#&#x6EDA;&#x8F6E;&#x4E8B;&#x4EF6;" class="headerlink" title="&#x6EDA;&#x8F6E;&#x4E8B;&#x4EF6;"></a>&#x6EDA;&#x8F6E;&#x4E8B;&#x4EF6;</h4><ul>
<li>mousewheel &#x4E8B;&#x4EF6;</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// &#x68C0;&#x67E5;&#x6D4F;&#x89C8;&#x5668;&#x662F;&#x5426;&#x652F;&#x6301;&#x4E0A;&#x9762;&#x6240;&#x6709;&#x7684;&#x4E8B;&#x4EF6;</span></div><div class="line"><span class="keyword">var</span> isSupported = <span class="built_in">document</span>.implementation.hasFeature(<span class="string">&quot;MouseEvent&quot;</span>, <span class="string">&quot;3.0&quot;</span>);</div></pre></td></tr></table></figure>
<h4 id="&#x5BA2;&#x6237;&#x533A;&#x5750;&#x6807;&#x4F4D;&#x7F6E;"><a href="#&#x5BA2;&#x6237;&#x533A;&#x5750;&#x6807;&#x4F4D;&#x7F6E;" class="headerlink" title="&#x5BA2;&#x6237;&#x533A;&#x5750;&#x6807;&#x4F4D;&#x7F6E;"></a>&#x5BA2;&#x6237;&#x533A;&#x5750;&#x6807;&#x4F4D;&#x7F6E;</h4><ul>
<li>event.clientX &#x4E8B;&#x4EF6;&#x53D1;&#x751F;&#x65F6;&#x9F20;&#x6807;&#x6307;&#x9488;&#x5728;&#x89C6;&#x53E3;&#x4E2D;&#x7684;&#x4F4D;&#x7F6E;</li>
<li>event.clientY &#x4E8B;&#x4EF6;&#x53D1;&#x751F;&#x65F6;&#x9F20;&#x6807;&#x6307;&#x9488;&#x5728;&#x89C6;&#x53E3;&#x4E2D;&#x7684;&#x4F4D;&#x7F6E;</li>
</ul>
<h4 id="&#x5C4F;&#x5E55;&#x5750;&#x6807;&#x4F4D;&#x7F6E;"><a href="#&#x5C4F;&#x5E55;&#x5750;&#x6807;&#x4F4D;&#x7F6E;" class="headerlink" title="&#x5C4F;&#x5E55;&#x5750;&#x6807;&#x4F4D;&#x7F6E;"></a>&#x5C4F;&#x5E55;&#x5750;&#x6807;&#x4F4D;&#x7F6E;</h4><ul>
<li>event.screenX &#x76F8;&#x5BF9;&#x4E8E;&#x6574;&#x4E2A;&#x7535;&#x8111;&#x5C4F;&#x5E55;&#x7684;&#x5750;&#x6807;&#x4F4D;&#x7F6E;</li>
<li>event.screenY &#x76F8;&#x5BF9;&#x4E8E;&#x6574;&#x4E2A;&#x7535;&#x8111;&#x5C4F;&#x5E55;&#x7684;&#x5750;&#x6807;&#x4F4D;&#x7F6E;</li>
</ul>
<h4 id="&#x952E;"><a href="#&#x952E;" class="headerlink" title="&#x952E;"></a>&#x952E;</h4><ul>
<li>shiftKey</li>
<li>ctrlKey</li>
<li>altKey</li>
<li>metaKey</li>
</ul>
<h4 id="&#x76F8;&#x5173;&#x5143;&#x7D20;"><a href="#&#x76F8;&#x5173;&#x5143;&#x7D20;" class="headerlink" title="&#x76F8;&#x5173;&#x5143;&#x7D20;"></a>&#x76F8;&#x5173;&#x5143;&#x7D20;</h4><p>&#x53D1;&#x751F; mouseover &#x548C; mouseout &#x65F6;&#xFF0C;&#x8FD8;&#x4F1A;&#x6D89;&#x53CA;&#x66F4;&#x591A;&#x7684;&#x5143;&#x7D20;&#x3002; DOM &#x901A;&#x8FC7; event &#x5BF9;&#x8C61;&#x7684; relatedTarget &#x5C5E;&#x6027;&#x63D0;&#x4F9B;&#x4E86;&#x76F8;&#x5173;&#x5143;&#x7D20;&#x4FE1;&#x606F;&#x3002;&#x5728; mouseover &#x4E8B;&#x4EF6;&#x89E6;&#x53D1;&#x65F6;&#xFF0C; IE &#x7684; fromElement &#x4FDD;&#x5B58;&#x4E86;&#x76F8;&#x5173;&#x5143;&#x7D20;&#xFF0C;&#x5728; mouseout &#x4E8B;&#x4EF6;&#x89E6;&#x53D1;&#x65F6;&#xFF0C;IE &#x7684; toElement &#x4FDD;&#x5B58;&#x4E86;&#x76F8;&#x5173;&#x5143;&#x7D20;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> EventUtill = {</div><div class="line">  <span class="attr">getRelatedTarget</span>: <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>{</div><div class="line">    <span class="keyword">if</span> (event.relatedTarget) {</div><div class="line">      <span class="keyword">return</span> event.relatedTarget;</div><div class="line">    } <span class="keyword">else</span> <span class="keyword">if</span> (event.toElement) {</div><div class="line">      <span class="keyword">return</span> event.toElement;</div><div class="line">    } <span class="keyword">else</span> <span class="keyword">if</span> (event.fromEvent) {</div><div class="line">      <span class="keyword">return</span> event.fromEvent;</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      <span class="keyword">return</span> <span class="literal">null</span>;</div><div class="line">    }</div><div class="line">  }</div><div class="line">}</div></pre></td></tr></table></figure>
<h3 id="&#x66F4;&#x591A;&#x4E8B;&#x4EF6;&#x4FE1;&#x606F;"><a href="#&#x66F4;&#x591A;&#x4E8B;&#x4EF6;&#x4FE1;&#x606F;" class="headerlink" title="&#x66F4;&#x591A;&#x4E8B;&#x4EF6;&#x4FE1;&#x606F;"></a>&#x66F4;&#x591A;&#x4E8B;&#x4EF6;&#x4FE1;&#x606F;</h3><p>DOM2 &#x7EA7;&#x4E8B;&#x4EF6;&#x89C4;&#x8303;&#x5728; event &#x5BF9;&#x8C61;&#x63D0;&#x4F9B;&#x4E86; detail &#x5C5E;&#x6027;&#xFF0C;&#x7528;&#x4E8E;&#x7ED9;&#x51FA;&#x6709;&#x5173;&#x4E8B;&#x4EF6;&#x7684;&#x66F4;&#x591A;&#x4FE1;&#x606F;&#x3002;&#x5305;&#x542B;&#x4E86;&#x4E00;&#x4E2A;&#x6570;&#x503C;&#x8868;&#x793A;&#x5355;&#x51FB;&#x4E86;&#x591A;&#x5C11;&#x6B21;&#x3002;</p>
<ul>
<li>altLeft</li>
<li>ctrlLeft</li>
<li>shiftLeft</li>
<li>offsetX</li>
<li>offsetY</li>
</ul>
<h3 id="&#x952E;&#x76D8;&#x548C;&#x6587;&#x4EF6;&#x5C5E;&#x6027;"><a href="#&#x952E;&#x76D8;&#x548C;&#x6587;&#x4EF6;&#x5C5E;&#x6027;" class="headerlink" title="&#x952E;&#x76D8;&#x548C;&#x6587;&#x4EF6;&#x5C5E;&#x6027;"></a>&#x952E;&#x76D8;&#x548C;&#x6587;&#x4EF6;&#x5C5E;&#x6027;</h3><ul>
<li>keydown&#xFF1A;&#x6309;&#x4E0B;&#x952E;&#x76D8;&#x4E0A;&#x7684;&#x4EFB;&#x610F;&#x952E;&#x89E6;&#x53D1;</li>
<li>keypress&#xFF1A;&#x6309;&#x4E0B;&#x952E;&#x76D8;&#x4E0A;&#x7684;&#x5B57;&#x7B26;&#x952E;&#x89E6;&#x53D1;</li>
<li>keyup&#xFF1A;&#x91CA;&#x653E;&#x952E;&#x76D8;&#x4E0A;&#x7684;&#x952E;&#x65F6;&#x89E6;&#x53D1;</li>
</ul>
<h4 id="&#x952E;&#x7801;"><a href="#&#x952E;&#x7801;" class="headerlink" title="&#x952E;&#x7801;"></a>&#x952E;&#x7801;</h4><ul>
<li>event.keyCode</li>
</ul>
<h4 id="textInput-&#x4E8B;&#x4EF6;"><a href="#textInput-&#x4E8B;&#x4EF6;" class="headerlink" title="textInput &#x4E8B;&#x4EF6;"></a>textInput &#x4E8B;&#x4EF6;</h4><ul>
<li>textInput &#x4E8B;&#x4EF6;</li>
<li>event.data &#x5C5E;&#x6027;&#x7684;&#x503C;&#x662F;&#x7528;&#x6237;&#x8F93;&#x5165;&#x7684;&#x5B57;&#x7B26;&#x3002;</li>
<li>event.inputMethod &#x5C5E;&#x6027;&#x8868;&#x793A;&#x628A;&#x6587;&#x672C;&#x8F93;&#x5165;&#x5230;&#x6587;&#x672C;&#x6846;&#x7684;&#x65B9;&#x5F0F;</li>
</ul>
<h3 id="&#x590D;&#x5408;&#x4E8B;&#x4EF6;"><a href="#&#x590D;&#x5408;&#x4E8B;&#x4EF6;" class="headerlink" title="&#x590D;&#x5408;&#x4E8B;&#x4EF6;"></a>&#x590D;&#x5408;&#x4E8B;&#x4EF6;</h3><ul>
<li>compositionstart</li>
<li>compositionupdate</li>
<li>compositionend</li>
</ul>
<h3 id="&#x53D8;&#x52A8;&#x4E8B;&#x4EF6;"><a href="#&#x53D8;&#x52A8;&#x4E8B;&#x4EF6;" class="headerlink" title="&#x53D8;&#x52A8;&#x4E8B;&#x4EF6;"></a>&#x53D8;&#x52A8;&#x4E8B;&#x4EF6;</h3><ul>
<li>DOMSubtreeModified</li>
<li>DOMNodeInserted</li>
<li>DOMNodeRemoved</li>
<li>DOMNodeInsertedIntoDocuemnt</li>
<li>DOMNodeRemovedFromDocuemnt</li>
<li>DOMAttrModified</li>
<li>DOMCharacterDataModified</li>
</ul>
<h3 id="HTML5-&#x4E8B;&#x4EF6;"><a href="#HTML5-&#x4E8B;&#x4EF6;" class="headerlink" title="HTML5 &#x4E8B;&#x4EF6;"></a>HTML5 &#x4E8B;&#x4EF6;</h3><ul>
<li>contexmenu &#x4E8B;&#x4EF6;</li>
<li>beforeunload &#x4E8B;&#x4EF6;</li>
<li>DOMContentLoaded &#x4E8B;&#x4EF6;</li>
<li>readystatechange &#x4E8B;&#x4EF6;<ul>
<li>uninitialized &#x5BF9;&#x8C61;&#x5C1A;&#x672A;&#x521D;&#x59CB;&#x5316;</li>
<li>loading &#x5BF9;&#x8C61;&#x6B63;&#x5728;&#x52A0;&#x8F7D;</li>
<li>loaded &#x5BF9;&#x8C61;&#x52A0;&#x8F7D;&#x6570;&#x636E;&#x5B8C;&#x6210;</li>
<li>interactive &#x53EF;&#x4EE5;&#x64CD;&#x4F5C;&#x5BF9;&#x8C61;&#x4E86;&#xFF0C;&#x4F46;&#x8FD8;&#x6CA1;&#x6709;&#x5B8C;&#x5168;&#x52A0;&#x8F7D;</li>
<li>complete &#x5BF9;&#x8C61;&#x5DF2;&#x7ECF;&#x52A0;&#x8F7D;&#x5B8C;&#x6BD5;</li>
</ul>
</li>
<li>pageshow &#x548C; pagehide &#x4E8B;&#x4EF6;</li>
<li>hashchange &#x4E8B;&#x4EF6;</li>
</ul>
<h3 id="&#x8BBE;&#x5907;&#x4E8B;&#x4EF6;"><a href="#&#x8BBE;&#x5907;&#x4E8B;&#x4EF6;" class="headerlink" title="&#x8BBE;&#x5907;&#x4E8B;&#x4EF6;"></a>&#x8BBE;&#x5907;&#x4E8B;&#x4EF6;</h3><ul>
<li>orientationonchange &#x4E8B;&#x4EF6;</li>
<li>MozOrientation &#x4E8B;&#x4EF6;</li>
<li>deviceorientation &#x4E8B;&#x4EF6; &#x8BBE;&#x5907;&#x5728;&#x7A7A;&#x95F4;&#x4E2D;&#x671D;&#x5411;&#x54EA;&#x91CC;<ul>
<li>alpha &#x5C5E;&#x6027;</li>
<li>beta &#x5C5E;&#x6027;</li>
<li>gamma &#x5C5E;&#x6027;</li>
<li>absolute &#x5C5E;&#x6027;</li>
<li>compassCalibrated &#x5C5E;&#x6027;</li>
</ul>
</li>
<li>devicemotion &#x4E8B;&#x4EF6;</li>
</ul>
<h3 id="&#x89E6;&#x6478;&#x4E0E;&#x624B;&#x52BF;&#x4E8B;&#x4EF6;"><a href="#&#x89E6;&#x6478;&#x4E0E;&#x624B;&#x52BF;&#x4E8B;&#x4EF6;" class="headerlink" title="&#x89E6;&#x6478;&#x4E0E;&#x624B;&#x52BF;&#x4E8B;&#x4EF6;"></a>&#x89E6;&#x6478;&#x4E0E;&#x624B;&#x52BF;&#x4E8B;&#x4EF6;</h3><ul>
<li>touchstart&#xFF1A;&#x624B;&#x52BF;&#x5728;&#x89E6;&#x6478;&#x5C4F;&#x65F6;&#x89E6;&#x53D1;</li>
<li>touchmove&#xFF1A;&#x624B;&#x52BF;&#x5728;&#x5C4F;&#x5E55;&#x4E0A;&#x6ED1;&#x52A8;&#x65F6;&#x89E6;&#x53D1;</li>
<li>touchend&#xFF1A;&#x624B;&#x52BF;&#x79BB;&#x5F00;&#x89E6;&#x6478;&#x5C4F;&#x65F6;&#x89E6;&#x53D1;</li>
<li>touchcansel&#xFF1A;&#x5F53;&#x7CFB;&#x7EDF;&#x505C;&#x6B62;&#x8DDF;&#x8E2A;&#x89E6;&#x6478;&#x65F6;&#x89E6;&#x53D1;</li>
<li>touches&#xFF1A;&#x8868;&#x793A;&#x5F53;&#x524D;&#x8DDF;&#x8E2A;&#x7684;&#x89E6;&#x6478;&#x64CD;&#x4F5C;&#x7684; Touch &#x5BF9;&#x8C61;&#x7684;&#x6570;&#x7EC4;</li>
<li>targetTouches&#xFF1A;&#x7279;&#x5B9A;&#x4E8E;&#x4E8B;&#x4EF6;&#x76EE;&#x6807;&#x7684; Touch &#x5BF9;&#x8C61;&#x7684;&#x6570;&#x7EC4;</li>
<li>changeTouches&#xFF1A;&#x8868;&#x793A;&#x81EA;&#x4E0A;&#x6B21;&#x89E6;&#x6478;&#x4EE5;&#x6765;&#x53D1;&#x751F;&#x4E86;&#x4EC0;&#x4E48;&#x6539;&#x53D8; Touch &#x5BF9;&#x8C61;&#x7684;&#x6570;&#x7EC4;</li>
</ul>
<p>&#x6BCF;&#x4E2A; touch &#x5BF9;&#x8C61;&#x5305;&#x542B;&#x4EE5;&#x4E0B;&#x5C5E;&#x6027;</p>
<ul>
<li>clientX</li>
<li>clientY</li>
<li>identitier</li>
<li>pageX</li>
<li>pageY</li>
<li>screenX</li>
<li>screenY</li>
<li>target</li>
</ul>
<h2 id="&#x5185;&#x5B58;&#x548C;&#x6027;&#x80FD;"><a href="#&#x5185;&#x5B58;&#x548C;&#x6027;&#x80FD;" class="headerlink" title="&#x5185;&#x5B58;&#x548C;&#x6027;&#x80FD;"></a>&#x5185;&#x5B58;&#x548C;&#x6027;&#x80FD;</h2><p>JavaScript &#x4E2D;&#xFF0C;&#x6DFB;&#x52A0;&#x5230;&#x9875;&#x9762;&#x4E0A;&#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x6570;&#x91CF;&#x5C06;&#x76F4;&#x63A5;&#x5173;&#x7CFB;&#x5230;&#x9875;&#x9762;&#x7684;&#x6574;&#x4F53;&#x8FD0;&#x884C;&#x6027;&#x80FD;&#x3002;</p>
<h3 id="&#x4E8B;&#x4EF6;&#x59D4;&#x6258;"><a href="#&#x4E8B;&#x4EF6;&#x59D4;&#x6258;" class="headerlink" title="&#x4E8B;&#x4EF6;&#x59D4;&#x6258;"></a>&#x4E8B;&#x4EF6;&#x59D4;&#x6258;</h3><p>&#x5BF9;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x8FC7;&#x591A;&#x7684;&#x95EE;&#x9898;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6CD5;&#x5C31;&#x662F; <strong>&#x4E8B;&#x4EF6;&#x59D4;&#x6258;</strong> &#x3002;&#x4E8B;&#x4EF6;&#x59D4;&#x6258;&#x5C31;&#x662F;&#x5229;&#x7528;&#x4E86;&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;&#xFF0C;&#x53EA;&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x6765;&#x7BA1;&#x7406;&#x67D0;&#x4E00;&#x7C7B;&#x578B;&#x7684;&#x7684;&#x6240;&#x6709;&#x4E8B;&#x4EF6;&#x3002;</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">ul</span> <span class="attr">id</span>=<span class="string">&quot;ulBox&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">li</span> <span class="attr">id</span>=<span class="string">&quot;li1&quot;</span>&gt;</span>1<span class="tag">&lt;/<span class="name">li</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">li</span> <span class="attr">id</span>=<span class="string">&quot;li2&quot;</span>&gt;</span>2<span class="tag">&lt;/<span class="name">li</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">li</span> <span class="attr">id</span>=<span class="string">&quot;li3&quot;</span>&gt;</span>3<span class="tag">&lt;/<span class="name">li</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">ul</span>&gt;</span></div></pre></td></tr></table></figure>
<p>&#x59D4;&#x6258;&#x4E8B;&#x4EF6;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> ul = <span class="built_in">document</span>.getElementById(<span class="string">&quot;ulBox&quot;</span>);</div><div class="line">EventUtil.addHandler(ul, <span class="string">&quot;click&quot;</span>, <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>{</div><div class="line">  event = EventUtil.getEvent(event);</div><div class="line">  <span class="keyword">var</span> target = EventUtil.getTarget(event);</div><div class="line">  <span class="keyword">switch</span> (target.id) {</div><div class="line">    <span class="keyword">case</span> <span class="string">&quot;li1&quot;</span>:</div><div class="line">      <span class="built_in">document</span>.title = <span class="string">&quot;I changed&quot;</span>;</div><div class="line">      <span class="keyword">break</span>;</div><div class="line">    <span class="keyword">case</span> <span class="string">&quot;li2&quot;</span>:</div><div class="line">      location.herf = <span class="string">&quot;http://www.baidu.com&quot;</span>;</div><div class="line">      <span class="keyword">break</span>;</div><div class="line">    <span class="keyword">case</span> <span class="string">&quot;li3&quot;</span>:</div><div class="line">      <span class="built_in">console</span>.log(<span class="string">&quot;Hi&quot;</span>);</div><div class="line">      <span class="keyword">break</span>;</div><div class="line">  }</div><div class="line">});</div></pre></td></tr></table></figure>
<h3 id="&#x79FB;&#x9664;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;"><a href="#&#x79FB;&#x9664;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;" class="headerlink" title="&#x79FB;&#x9664;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;"></a>&#x79FB;&#x9664;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">btn.onclick = <span class="literal">null</span>;</div></pre></td></tr></table></figure>
<h3 id="&#x7981;&#x6B62;a&#x6807;&#x7B7E;&#x7684;&#x9ED8;&#x8BA4;&#x884C;&#x4E3A;"><a href="#&#x7981;&#x6B62;a&#x6807;&#x7B7E;&#x7684;&#x9ED8;&#x8BA4;&#x884C;&#x4E3A;" class="headerlink" title="&#x7981;&#x6B62;a&#x6807;&#x7B7E;&#x7684;&#x9ED8;&#x8BA4;&#x884C;&#x4E3A;"></a>&#x7981;&#x6B62;a&#x6807;&#x7B7E;&#x7684;&#x9ED8;&#x8BA4;&#x884C;&#x4E3A;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">onclick = <span class="string">&quot;return false;&quot;</span></div></pre></td></tr></table></figure>
<h2 id="&#x4E00;&#x4E2A;&#x5224;&#x65AD;&#x5BA2;&#x6237;&#x7AEF;&#x662F;-PC-&#x7AEF;&#x8FD8;&#x662F;&#x79FB;&#x52A8;&#x7AEF;&#x7684;&#x7A0B;&#x5E8F;"><a href="#&#x4E00;&#x4E2A;&#x5224;&#x65AD;&#x5BA2;&#x6237;&#x7AEF;&#x662F;-PC-&#x7AEF;&#x8FD8;&#x662F;&#x79FB;&#x52A8;&#x7AEF;&#x7684;&#x7A0B;&#x5E8F;" class="headerlink" title="&#x4E00;&#x4E2A;&#x5224;&#x65AD;&#x5BA2;&#x6237;&#x7AEF;&#x662F; PC &#x7AEF;&#x8FD8;&#x662F;&#x79FB;&#x52A8;&#x7AEF;&#x7684;&#x7A0B;&#x5E8F;"></a>&#x4E00;&#x4E2A;&#x5224;&#x65AD;&#x5BA2;&#x6237;&#x7AEF;&#x662F; PC &#x7AEF;&#x8FD8;&#x662F;&#x79FB;&#x52A8;&#x7AEF;&#x7684;&#x7A0B;&#x5E8F;</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">document</span>.getElementById(<span class="string">&quot;txt&quot;</span>).onkeydown=<span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>{ <span class="built_in">console</span>.log(e.keyCode); };</div><div class="line"><span class="built_in">window</span>.onresize=<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>{</div><div class="line">  <span class="keyword">if</span> (<span class="built_in">document</span>.body.clientWidth&gt;<span class="number">960</span>) {</div><div class="line">        <span class="built_in">console</span>.log(<span class="string">&quot;&#x60A8;&#x7528;&#x7684;&#x662F;&#x7535;&#x8111;&#x6D4F;&#x89C8;&#x7684;&#x8BE5;&#x9875;&#x9762;&quot;</span>);</div><div class="line">    }<span class="keyword">else</span> <span class="keyword">if</span>(<span class="built_in">document</span>.body.clientWidth&gt;<span class="number">500</span>){</div><div class="line">        <span class="built_in">console</span>.log(<span class="string">&quot;&#x60A8;&#x7528;&#x7684;&#x662F;&#x5E73;&#x677F;&#x6D4F;&#x89C8;&#x7684;&#x8BE5;&#x9875;&#x9762;&quot;</span>);</div><div class="line">    }<span class="keyword">else</span>{</div><div class="line">        <span class="built_in">console</span>.log(<span class="string">&quot;&#x60A8;&#x7528;&#x7684;&#x662F;&#x624B;&#x673A;&#x6D4F;&#x89C8;&#x7684;&#x9875;&#x9762;&quot;</span>);</div><div class="line">    }</div><div class="line">  }</div><div class="line">}; <span class="comment">// &#x5224;&#x65AD;&#x6D4F;&#x89C8;&#x5668;&#x7A97;&#x53E3;&#x5927;&#x5C0F;</span></div><div class="line"><span class="built_in">document</span>.onclick=<span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>{   </div><div class="line">  <span class="built_in">document</span>.title = e.screenX+<span class="string">&quot;===&quot;</span>+e.screenY; <span class="comment">//screenX&#x548C;screenY&#x662F;&#x76F8;&#x5BF9;&#x4E8E;&#x5C4F;&#x5E55;&#x7684;&#x5DE6;&#x4E0A;&#x89D2;</span></div><div class="line">    <span class="built_in">console</span>.log(e);</div><div class="line">};</div></pre></td></tr></table></figure>
<h2 id="&#x56FE;&#x7247;&#x8DDF;&#x7740;&#x9F20;&#x6807;&#x98DE;"><a href="#&#x56FE;&#x7247;&#x8DDF;&#x7740;&#x9F20;&#x6807;&#x98DE;" class="headerlink" title="&#x56FE;&#x7247;&#x8DDF;&#x7740;&#x9F20;&#x6807;&#x98DE;"></a>&#x56FE;&#x7247;&#x8DDF;&#x7740;&#x9F20;&#x6807;&#x98DE;</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">document</span>.onmousemove=<span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>{</div><div class="line">  e=e||<span class="built_in">window</span>.event; <span class="comment">// &#x517C;&#x5BB9;&#x4EE3;&#x7801;</span></div><div class="line">  <span class="built_in">document</span>.title=e.clientX+<span class="string">&quot;===&quot;</span>+e.clientY; <span class="comment">// clientX&#x548C;clientY----&#x4E8B;&#x4EF6;&#x53C2;&#x6570;&#x83B7;&#x53D6;</span></div><div class="line">  imgObj.style.position=<span class="string">&quot;absolute&quot;</span>;</div><div class="line">  imgObj.style.left=e.clientX+<span class="string">&quot;px&quot;</span>;</div><div class="line">      imgObj.style.top=e.clientY+<span class="string">&quot;px&quot;</span>;</div><div class="line">  imgObj.style.left=e.pageX+<span class="string">&quot;px&quot;</span>; <span class="comment">//pageX--&#x5305;&#x542B;&#x53EF;&#x89C6;&#x533A;&#x57DF;&#x7684;&#x6A2A;&#x5750;&#x6807;&#x548C;&#x9690;&#x85CF;&#x533A;&#x57DF;</span></div><div class="line">      imgObj.style.top=e.pageY+<span class="string">&quot;px&quot;</span>; <span class="comment">//pageY---&#x5305;&#x542B;&#x53EF;&#x89C6;&#x533A;&#x57DF;&#x7684;&#x7EB5;&#x5750;&#x6807;&#x548C;&#x9690;&#x85CF;&#x533A;&#x57DF;</span></div><div class="line">}&#xFF1B;</div></pre></td></tr></table></figure>
<h2 id="&#x6A21;&#x62DF;&#x591A;&#x4EBA;&#x5F00;&#x53D1;&#x6CE8;&#x518C;&#x4E8B;&#x4EF6;"><a href="#&#x6A21;&#x62DF;&#x591A;&#x4EBA;&#x5F00;&#x53D1;&#x6CE8;&#x518C;&#x4E8B;&#x4EF6;" class="headerlink" title="&#x6A21;&#x62DF;&#x591A;&#x4EBA;&#x5F00;&#x53D1;&#x6CE8;&#x518C;&#x4E8B;&#x4EF6;"></a>&#x6A21;&#x62DF;&#x591A;&#x4EBA;&#x5F00;&#x53D1;&#x6CE8;&#x518C;&#x4E8B;&#x4EF6;</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">addEvent</span>(<span class="params">element, eventName, fn</span>) </span>{</div><div class="line">    <span class="keyword">var</span> oldEvent=element[<span class="string">&quot;on&quot;</span>+eventName];</div><div class="line">    <span class="keyword">if</span>(oldEvent==<span class="literal">null</span>){<span class="comment">//&#x8868;&#x793A;&#x8BE5;&#x4E8B;&#x4EF6;&#x6CA1;&#x6709;&#x5904;&#x7406;&#x51FD;&#x6570;</span></div><div class="line">        element[<span class="string">&quot;on&quot;</span>+eventName]=fn;<span class="comment">//&#x6CE8;&#x518C;&#x4E8B;&#x4EF6;&#x4E86;</span></div><div class="line">    }<span class="keyword">else</span>{</div><div class="line">        <span class="comment">//&#x6709;&#x4E8B;&#x4EF6;&#x4E86;---&#x5148;&#x8C03;&#x7528;&#x539F;&#x6765;&#x7684;&#x4E8B;&#x4EF6;,&#x518D;&#x91CD;&#x65B0;&#x6CE8;&#x518C;&#x65B0;&#x7684;&#x4E8B;&#x4EF6;</span></div><div class="line">        element[<span class="string">&quot;on&quot;</span>+eventName]=<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>{</div><div class="line">            <span class="comment">//&#x8C03;&#x7528;&#x539F;&#x6765;&#x7684;&#x4E8B;&#x4EF6;-&#x6CE8;&#x518C;&#x65B0;&#x7684;&#x4E8B;&#x4EF6;</span></div><div class="line">            oldEvent();</div><div class="line">            fn();</div><div class="line">        };</div><div class="line">    }</div><div class="line">}</div></pre></td></tr></table></figure>
<h2 id="&#x6CE8;&#x518C;&#x591A;&#x4E2A;&#x4E8B;&#x4EF6;"><a href="#&#x6CE8;&#x518C;&#x591A;&#x4E2A;&#x4E8B;&#x4EF6;" class="headerlink" title="&#x6CE8;&#x518C;&#x591A;&#x4E2A;&#x4E8B;&#x4EF6;"></a>&#x6CE8;&#x518C;&#x591A;&#x4E2A;&#x4E8B;&#x4EF6;</h2><blockquote>
<p>&#x4E09;&#x79CD;&#x6CE8;&#x518C;&#x4E8B;&#x4EF6;&#x7684;&#x65B9;&#x5F0F;:</p>
</blockquote>
<ul>
<li>&#x5BF9;&#x8C61;.on&#x4E8B;&#x4EF6;&#x540D;&#x5B57;=&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x51FD;&#x6570;;</li>
<li>&#x5BF9;&#x8C61;.addEventListener(&#x201C;&#x4E8B;&#x4EF6;&#x7684;&#x540D;&#x5B57;&#x201D;,&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x51FD;&#x6570;,false);</li>
<li>&#x5BF9;&#x8C61;.attachEvent(&#x201C;on&#x4E8B;&#x4EF6;&#x7684;&#x540D;&#x5B57;&#x201D;,&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x51FD;&#x6570;);</li>
<li>&#x6CE8;&#x518C;&#x4E8B;&#x4EF6;&#x65B9;&#x5F0F;&#x7684;&#x533A;&#x522B;:<ul>
<li>btnObj.onclick=fn;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x4EFB;&#x4F55;&#x6D4F;&#x89C8;&#x5668;&#x90FD;&#x652F;&#x6301;</li>
<li>btnObj.addEventListener();&#x8C37;&#x6B4C;&#x548C;&#x706B;&#x72D0;&#x6D4F;&#x89C8;&#x5668;&#x652F;&#x6301;</li>
<li>btnObj.attachEvent();IE8&#x652F;&#x6301;</li>
</ul>
</li>
<li>&#x540C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x540C;&#x65F6;&#x6CE8;&#x518C;&#x591A;&#x4E2A;&#x76F8;&#x540C;&#x7684;&#x4E8B;&#x4EF6;&#xFF0C;addEventListener&#x548C;attachEvent&#x533A;&#x522B;:<ul>
<li>&#x524D;&#x8005;&#x4E09;&#x4E2A;&#x53C2;&#x6570;,&#x540E;&#x8005;&#x4E24;&#x4E2A;&#x53C2;&#x6570;</li>
<li>&#x524D;&#x8005;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x4E8B;&#x4EF6;&#x7684;&#x540D;&#x5B57;&#xFF0C;&#x6CA1;&#x6709;on</li>
<li>&#x540E;&#x8005;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x4E8B;&#x4EF6;&#x7684;&#x540D;&#x5B57;,&#x6709;on</li>
<li>addEventListener&#x65B9;&#x6CD5;&#x4E2D;&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x5982;&#x679C;&#x662F;false&#x5219;&#x662F;&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;,&#x5982;&#x679C;&#x662F;true&#x5219;&#x662F;&#x4E8B;&#x4EF6;&#x6355;&#x83B7;</li>
</ul>
</li>
</ul>
<h2 id="&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;&#x9636;&#x6BB5;&#x5224;&#x65AD;"><a href="#&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;&#x9636;&#x6BB5;&#x5224;&#x65AD;" class="headerlink" title="&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;&#x9636;&#x6BB5;&#x5224;&#x65AD;"></a>&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;&#x9636;&#x6BB5;&#x5224;&#x65AD;</h2><ul>
<li>&#x901A;&#x8FC7;&#x4E8B;&#x4EF6;&#x53C2;&#x6570;&#x2013;e.eventPhase &#x53EF;&#x4EE5;&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x4E8B;&#x4EF6;&#x7ECF;&#x5386;&#x7684;&#x662F;&#x4EC0;&#x4E48;&#x9636;&#x6BB5;</li>
<li>&#x5982;&#x679C;&#x662F;1&#x5219;&#x662F;&#x6355;&#x83B7;&#x9636;&#x6BB5;</li>
<li>&#x5982;&#x679C;&#x662F;2&#x5219;&#x662F;&#x76EE;&#x6807;&#x9636;&#x6BB5;:&#x7B2C;&#x4E00;&#x6B21;&#x70B9;&#x8C01;&#x8C01;&#x5C31;&#x662F;&#x76EE;&#x6807;</li>
<li>&#x76EE;&#x6807;&#x9636;&#x6BB5;&#x4E4B;&#x540E;&#x5C31;&#x662F;&#x5192;&#x6CE1;&#x9636;&#x6BB5;</li>
<li>&#x4EE5;&#x4E0A;&#x662F;&#x7ED3;&#x5408;&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x662F;false&#x7684;&#x60C5;&#x51B5;&#x800C;&#x8A00;</li>
<li>&#x53E6;&#x4E00;&#x79CD;&#x60C5;&#x51B5;:&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x662F;true&#x7684;&#x65F6;&#x5019;,&#x53EA;&#x6709;&#x6355;&#x83B7;&#x9636;&#x6BB5;&#x548C;&#x76EE;&#x6807;&#x9636;&#x6BB5;</li>
<li>&#x5148;&#x6355;&#x83B7;,&#x7136;&#x540E;&#x518D;&#x76EE;&#x6807;</li>
<li>&#x4E00;&#x822C;&#x7F51;&#x9875;&#x4E2D;&#x90FD;&#x662F;&#x6709;&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;&#x7684;,&#x4E00;&#x822C;&#x60C5;&#x51B5;&#x6211;&#x4EEC;&#x4E0D;&#x7528;&#x6355;&#x83B7;</li>
</ul>
<h2 id="&#x963B;&#x6B62;&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;"><a href="#&#x963B;&#x6B62;&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;" class="headerlink" title="&#x963B;&#x6B62;&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;"></a>&#x963B;&#x6B62;&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;</h2><p>&#x4E24;&#x79CD;&#x65B9;&#x5F0F;: </p>
<ul>
<li>&#x7B2C;&#x4E00;&#x79CD;:&#x65B9;&#x6CD5; e.stopPropagation();</li>
<li>&#x7B2C;&#x4E8C;&#x79CD;:&#x5C5E;&#x6027; window.event.cancelBubble=true;</li>
</ul>
<h2 id="&#x6709;&#x5173;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7684;&#x51FD;&#x6570;&#x7684;&#x5C01;&#x88C5;"><a href="#&#x6709;&#x5173;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7684;&#x51FD;&#x6570;&#x7684;&#x5C01;&#x88C5;" class="headerlink" title="&#x6709;&#x5173;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7684;&#x51FD;&#x6570;&#x7684;&#x5C01;&#x88C5;"></a>&#x6709;&#x5173;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7684;&#x51FD;&#x6570;&#x7684;&#x5C01;&#x88C5;</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> EventUtil = {</div><div class="line">  <span class="attr">addHandler</span>: <span class="function"><span class="keyword">function</span>(<span class="params">element, type, handler</span>) </span>{</div><div class="line">    <span class="keyword">if</span> (element.addEventListener) {</div><div class="line">      element.addEventListener(type, handler, <span class="literal">false</span>);</div><div class="line">    } <span class="keyword">else</span> <span class="keyword">if</span> (element.attachEvent) {</div><div class="line">      element.attachEvent(<span class="string">&quot;on&quot;</span> + type, handler);</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      element[<span class="string">&quot;on&quot;</span> + type] = <span class="literal">null</span>;</div><div class="line">    }</div><div class="line">  },</div><div class="line">  <span class="attr">removeHandler</span>: <span class="function"><span class="keyword">function</span>(<span class="params">element, type, handler</span>) </span>{</div><div class="line">    <span class="keyword">if</span> (element.removeListener) {</div><div class="line">      element.removeListener(type, handler, <span class="literal">false</span>);</div><div class="line">    } <span class="keyword">else</span> <span class="keyword">if</span> (element.detachEvent) {</div><div class="line">      element.detachEvent(<span class="string">&quot;on&quot;</span> + type, handler);</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      element[<span class="string">&quot;on&quot;</span> + type] = <span class="literal">null</span>;</div><div class="line">    }</div><div class="line">  },</div><div class="line">  <span class="attr">getEvent</span>: <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>{</div><div class="line">    <span class="keyword">return</span> event ? event : <span class="built_in">window</span>.event;</div><div class="line">  },</div><div class="line">  <span class="attr">getTarget</span>: <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>{</div><div class="line">    <span class="keyword">return</span> event.target || event.srcElement;</div><div class="line">  },</div><div class="line">  <span class="attr">preventDefault</span>: <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>{</div><div class="line">    <span class="keyword">if</span> (event.preventDefault) {</div><div class="line">      event.preventDefault;</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      event.returnValue = <span class="literal">false</span>;</div><div class="line">    }</div><div class="line">  },</div><div class="line">  <span class="attr">stopPropagation</span>: <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>{</div><div class="line">    <span class="keyword">if</span> (event.stopPropagation) {</div><div class="line">      event.stopPropagation;</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      event.cancelBubble = <span class="literal">true</span>;</div><div class="line">    }</div><div class="line">  },</div><div class="line">  <span class="attr">getRelatedTarget</span>: <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>{</div><div class="line">    <span class="keyword">if</span> (event.relatedTarget) {</div><div class="line">      <span class="keyword">return</span> event.relatedTarget;</div><div class="line">    } <span class="keyword">else</span> <span class="keyword">if</span> (event.toElement) {</div><div class="line">      <span class="keyword">return</span> event.toElement;</div><div class="line">    } <span class="keyword">else</span> <span class="keyword">if</span> (event.fromEvent) {</div><div class="line">      <span class="keyword">return</span> event.fromEvent;</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      <span class="keyword">return</span> <span class="literal">null</span>;</div><div class="line">    }</div><div class="line">  },</div><div class="line">  <span class="attr">getWheelDelta</span>: <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>{</div><div class="line">    <span class="keyword">if</span> (event.wheelDelta) {</div><div class="line">      <span class="keyword">return</span> (client.engine.opera &amp;&amp; client.engine.opera &lt; <span class="number">9.5</span> ? -event.wheelDelta : event.wheelDelta);</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      <span class="keyword">return</span> -event.detail * <span class="number">40</span>;</div><div class="line">    }</div><div class="line">  },</div><div class="line">  <span class="attr">getCharCode</span>: <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>{</div><div class="line">    <span class="keyword">if</span> (<span class="keyword">typeof</span> event.charCode == <span class="string">&quot;number&quot;</span>) {</div><div class="line">      <span class="keyword">return</span> event.charCode;</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      <span class="keyword">return</span> event.keyCode;</div><div class="line">    }</div><div class="line">  },</div><div class="line">  <span class="attr">getClipboardText</span>: <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>{</div><div class="line">    <span class="keyword">var</span> clipboardData = (event.clipboardData || <span class="built_in">window</span>.clipboardData);</div><div class="line">    <span class="keyword">return</span> clipboardData.getData(<span class="string">&quot;text&quot;</span>);</div><div class="line">  },</div><div class="line">  <span class="attr">setClipboardText</span>: <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>{</div><div class="line">    <span class="keyword">if</span> (event.clipboardData) {</div><div class="line">      <span class="keyword">return</span> event.clipboardData.setData(<span class="string">&quot;text/plain&quot;</span>, value);</div><div class="line">    } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="built_in">window</span>.clipboardData) {</div><div class="line">      <span class="keyword">return</span> <span class="built_in">window</span>.clipboardData.setData(<span class="string">&quot;text/plain&quot;</span>, value);</div><div class="line">    }</div><div class="line">  }</div><div class="line">}</div></pre></td></tr></table></figure>
<h2 id="&#x52A8;&#x753B;&#x51FD;&#x6570;&#x5C01;&#x88C5;&#xFF08;js&#xFF09;"><a href="#&#x52A8;&#x753B;&#x51FD;&#x6570;&#x5C01;&#x88C5;&#xFF08;js&#xFF09;" class="headerlink" title="&#x52A8;&#x753B;&#x51FD;&#x6570;&#x5C01;&#x88C5;&#xFF08;js&#xFF09;"></a>&#x52A8;&#x753B;&#x51FD;&#x6570;&#x5C01;&#x88C5;&#xFF08;js&#xFF09;</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div></pre></td><td class="code"><pre><div class="line"><span class="comment">//&#x6839;&#x636E;id&#x83B7;&#x53D6;&#x5BF9;&#x5E94;&#x7684;&#x5143;&#x7D20;</span></div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">my$</span>(<span class="params">id</span>) </span>{</div><div class="line">    <span class="keyword">return</span> <span class="built_in">document</span>.getElementById(id);</div><div class="line">}</div><div class="line"><span class="comment">/*</span></div><div class="line">* element---&#x4EFB;&#x610F;&#x7684;&#x5143;&#x7D20;</div><div class="line">* attr---&#x5C5E;&#x6027;</div><div class="line">* */</div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">getAttrValue</span>(<span class="params">element,attr</span>) </span>{</div><div class="line">    <span class="keyword">return</span> element.currentStyle ? element.currentStyle[attr] : <span class="built_in">window</span>.getComputedStyle(element,<span class="literal">null</span>)[attr]||<span class="number">0</span>;</div><div class="line">}</div><div class="line"><span class="comment">/*</span></div><div class="line">* element----&#x8981;&#x79FB;&#x52A8;&#x7684;&#x5143;&#x7D20;</div><div class="line">* target----&#x79FB;&#x52A8;&#x7684;&#x76EE;&#x6807;</div><div class="line">* &#x521D;&#x7EA7;&#x7248;&#x672C;</div><div class="line">* */</div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">animate1</span>(<span class="params">element,target</span>) </span>{</div><div class="line">    clearInterval(element.timeId);</div><div class="line">    element.timeId=setInterval(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>{</div><div class="line">        <span class="comment">//&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x7684;&#x4F4D;&#x7F6E;</span></div><div class="line">        <span class="keyword">var</span> current=element.offsetLeft;</div><div class="line">        <span class="comment">//&#x6BCF;&#x6B21;&#x79FB;&#x52A8;&#x591A;&#x5C11;&#x6B65;</span></div><div class="line">        <span class="keyword">var</span> step=(target-current)/<span class="number">10</span>;<span class="comment">//(&#x76EE;&#x6807;-&#x5F53;&#x524D;)/10</span></div><div class="line">        step=step&gt;<span class="number">0</span>?<span class="built_in">Math</span>.ceil(step):<span class="built_in">Math</span>.floor(step);</div><div class="line">        current=current+step;</div><div class="line">        element.style.left=current+<span class="string">&quot;px&quot;</span>;</div><div class="line">        <span class="keyword">if</span>(current==target){</div><div class="line">            clearInterval(element.timeId);</div><div class="line">        }</div><div class="line">        <span class="built_in">console</span>.log(<span class="string">&quot;target:&quot;</span>+target+<span class="string">&quot;current:&quot;</span>+current+<span class="string">&quot;step:&quot;</span>+step);</div><div class="line">    },<span class="number">10</span>);</div><div class="line">}</div><div class="line"><span class="comment">/*</span></div><div class="line">* &#x7EC8;&#x6781;&#x7248;&#x672C;&#x7684;&#x52A8;&#x753B;&#x51FD;&#x6570;</div><div class="line">* */</div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">animate</span>(<span class="params">element,json,fn</span>) </span>{</div><div class="line">    clearInterval(element.timeId);</div><div class="line">    element.timeId=setInterval(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>{</div><div class="line">        <span class="keyword">var</span> flag=<span class="literal">true</span>;<span class="comment">//&#x5047;&#x8BBE;&#x90FD;&#x8FBE;&#x5230;&#x4E86;&#x76EE;&#x6807;</span></div><div class="line">        <span class="keyword">for</span>(<span class="keyword">var</span> attr <span class="keyword">in</span> json){</div><div class="line">            <span class="keyword">if</span>(attr==<span class="string">&quot;opacity&quot;</span>){<span class="comment">//&#x5224;&#x65AD;&#x5C5E;&#x6027;&#x662F;&#x4E0D;&#x662F;opacity</span></div><div class="line">                <span class="keyword">var</span> current= getAttrValue(element,attr)*<span class="number">100</span>;</div><div class="line">                <span class="comment">//&#x6BCF;&#x6B21;&#x79FB;&#x52A8;&#x591A;&#x5C11;&#x6B65;</span></div><div class="line">                <span class="keyword">var</span> target=json[attr]*<span class="number">100</span>;<span class="comment">//&#x76F4;&#x63A5;&#x8D4B;&#x503C;&#x7ED9;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;,&#x540E;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x90FD;&#x4E0D;&#x7528;&#x6539;</span></div><div class="line">                <span class="keyword">var</span> step=(target-current)/<span class="number">10</span>;<span class="comment">//(&#x76EE;&#x6807;-&#x5F53;&#x524D;)/10</span></div><div class="line">                step=step&gt;<span class="number">0</span>?<span class="built_in">Math</span>.ceil(step):<span class="built_in">Math</span>.floor(step);</div><div class="line">                current=current+step;</div><div class="line">                element.style[attr]=current/<span class="number">100</span>;</div><div class="line">            }<span class="keyword">else</span> <span class="keyword">if</span>(attr==<span class="string">&quot;zIndex&quot;</span>){<span class="comment">//&#x5224;&#x65AD;&#x5C5E;&#x6027;&#x662F;&#x4E0D;&#x662F;zIndex</span></div><div class="line">                element.style[attr]=json[attr];</div><div class="line">            }<span class="keyword">else</span>{<span class="comment">//&#x666E;&#x901A;&#x7684;&#x5C5E;&#x6027;</span></div><div class="line">                <span class="comment">//&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x7684;&#x4F4D;&#x7F6E;----getAttrValue(element,attr)&#x83B7;&#x53D6;&#x7684;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#x7C7B;&#x578B;</span></div><div class="line">                <span class="keyword">var</span> current= <span class="built_in">parseInt</span>(getAttrValue(element,attr))||<span class="number">0</span>;</div><div class="line">                <span class="comment">//&#x6BCF;&#x6B21;&#x79FB;&#x52A8;&#x591A;&#x5C11;&#x6B65;</span></div><div class="line">                <span class="keyword">var</span> target=json[attr];<span class="comment">//&#x76F4;&#x63A5;&#x8D4B;&#x503C;&#x7ED9;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;,&#x540E;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x90FD;&#x4E0D;&#x7528;&#x6539;</span></div><div class="line">                <span class="keyword">var</span> step=(target-current)/<span class="number">10</span>;<span class="comment">//(&#x76EE;&#x6807;-&#x5F53;&#x524D;)/10</span></div><div class="line">                step=step&gt;<span class="number">0</span>?<span class="built_in">Math</span>.ceil(step):<span class="built_in">Math</span>.floor(step);</div><div class="line">                current=current+step;</div><div class="line">                element.style[attr]=current+<span class="string">&quot;px&quot;</span>;</div><div class="line">            }</div><div class="line">            <span class="keyword">if</span>(current!=target){</div><div class="line">                flag=<span class="literal">false</span>;<span class="comment">//&#x5982;&#x679C;&#x6CA1;&#x5230;&#x76EE;&#x6807;&#x7ED3;&#x679C;&#x5C31;&#x4E3A;false</span></div><div class="line">            }</div><div class="line">        }</div><div class="line">        <span class="keyword">if</span>(flag){<span class="comment">//&#x7ED3;&#x679C;&#x4E3A;true</span></div><div class="line">            clearInterval(element.timeId);</div><div class="line">            <span class="keyword">if</span>(fn){<span class="comment">//&#x5982;&#x679C;&#x7528;&#x6237;&#x4F20;&#x5165;&#x4E86;&#x56DE;&#x8C03;&#x7684;&#x51FD;&#x6570;</span></div><div class="line">                fn(); <span class="comment">//&#x5C31;&#x76F4;&#x63A5;&#x7684;&#x8C03;&#x7528;,</span></div><div class="line">            }</div><div class="line">        }</div><div class="line">        <span class="built_in">console</span>.log(<span class="string">&quot;target:&quot;</span>+target+<span class="string">&quot;current:&quot;</span>+current+<span class="string">&quot;step:&quot;</span>+step);</div><div class="line">    },<span class="number">10</span>);</div><div class="line">}</div></pre></td></tr></table></figure>
<h2 id="&#x603B;&#x7ED3;&#x4E09;&#x5927;&#x7CFB;&#x5217;"><a href="#&#x603B;&#x7ED3;&#x4E09;&#x5927;&#x7CFB;&#x5217;" class="headerlink" title="&#x603B;&#x7ED3;&#x4E09;&#x5927;&#x7CFB;&#x5217;"></a>&#x603B;&#x7ED3;&#x4E09;&#x5927;&#x7CFB;&#x5217;</h2><pre><code>clientX  clientY  clientWidth  clientHeight
pageX  pageY  pageWidth pageHeight
offsetLeft offsetTop  offsetWidth offsetHeight
</code></pre>
      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div>感谢您的支持！</div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>打 赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="http://ofy7k3v4s.bkt.clouddn.com/wcpayCode.jpg" alt="Hongqin Ma WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
        <div id="alipay" style="display: inline-block">
          <img id="alipay_qr" src="http://ofy7k3v4s.bkt.clouddn.com/apayCode.jpg" alt="Hongqin Ma Alipay"/>
          <p>支付宝打赏</p>
        </div>
      
    </div>
  </div>


      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/js/" rel="tag">#js</a>
          
            <a href="/tags/事件/" rel="tag">#事件</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2014/09/22/17-DOM-文档对象模型/" rel="next" title="DOM-文档对象模型">
                <i class="fa fa-chevron-left"></i> DOM-文档对象模型
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2014/10/28/19-js-的表单/" rel="prev" title="js 的表单">
                js 的表单 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <div class="ds-share flat" data-thread-key="2014/10/14/18-js-的事件/"
     data-title="js 的事件"
     data-content=""
     data-url="https://hongqinma.github.io/2014/10/14/18-js-的事件/">
  <div class="ds-share-inline">
    <ul  class="ds-share-icons-16">

      <li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
      <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
      <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
      <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
      <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>

    </ul>
    <div class="ds-share-icons-more">
    </div>
  </div>
</div>
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2014/10/14/18-js-的事件/"
           data-title="js 的事件" data-url="https://hongqinma.github.io/2014/10/14/18-js-的事件/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Overview
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/photo.jpg"
               alt="Hongqin Ma" />
          <p class="site-author-name" itemprop="name">Hongqin Ma</p>
          <p class="site-description motion-element" itemprop="description">Spell at all costs， to rush you in the future. </p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">68</span>
              <span class="site-state-item-name">posts</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">16</span>
                <span class="site-state-item-name">categories</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">57</span>
                <span class="site-state-item-name">tags</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/HongqinMa" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/HongqinMa" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.facebook.com/profile.php?id=100006581058735" target="_blank" title="Facebook">
                  
                    <i class="fa fa-fw fa-facebook"></i>
                  
                  Facebook
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.zhihu.com/people/HirakuMa" target="_blank" title="知乎">
                  
                    <i class="fa fa-fw fa-share-alt"></i>
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Links
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/rubylouvre/" title="司徒正美" target="_blank">司徒正美</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/sanshi/" title="三生石上" target="_blank">三生石上</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/TomXu/" title="汤姆大叔" target="_blank">汤姆大叔</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://gold.xitu.io/" title="掘金" target="_blank">掘金</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://segmentfault.com/" title="segmentfault" target="_blank">segmentfault</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.jianshu.com/users/1cbb94e5ed4d/latest_articles" title="简书" target="_blank">简书</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://home.cnblogs.com/" title="博客园" target="_blank">博客园</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://www.awesomes.cn/" title="Awesomes" target="_blank">Awesomes</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#事件流"><span class="nav-number">1.</span> <span class="nav-text">事件流</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#事件冒泡"><span class="nav-number">1.1.</span> <span class="nav-text">事件冒泡</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#事件捕获"><span class="nav-number">1.2.</span> <span class="nav-text">事件捕获</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#DOM-事件流"><span class="nav-number">1.3.</span> <span class="nav-text">DOM 事件流</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#事件处理程序"><span class="nav-number">2.</span> <span class="nav-text">事件处理程序</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#HTML-事件处理程序"><span class="nav-number">2.1.</span> <span class="nav-text">HTML 事件处理程序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#DOM0-级事件处理程序"><span class="nav-number">2.2.</span> <span class="nav-text">DOM0 级事件处理程序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#DOM2-级事件处理程序"><span class="nav-number">2.3.</span> <span class="nav-text">DOM2 级事件处理程序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#IE-的事件处理程序"><span class="nav-number">2.4.</span> <span class="nav-text">IE 的事件处理程序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#跨浏览器的事件处理程序"><span class="nav-number">2.5.</span> <span class="nav-text">跨浏览器的事件处理程序</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#事件对象"><span class="nav-number">3.</span> <span class="nav-text">事件对象</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#DOM-中的事件对象"><span class="nav-number">3.1.</span> <span class="nav-text">DOM 中的事件对象</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#IE-中的事件对象"><span class="nav-number">3.2.</span> <span class="nav-text">IE 中的事件对象</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#跨浏览器的事件对象"><span class="nav-number">3.3.</span> <span class="nav-text">跨浏览器的事件对象</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#事件类型"><span class="nav-number">4.</span> <span class="nav-text">事件类型</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#UI-事件"><span class="nav-number">4.1.</span> <span class="nav-text">UI 事件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#焦点事件"><span class="nav-number">4.2.</span> <span class="nav-text">焦点事件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#鼠标与滚轮事件"><span class="nav-number">4.3.</span> <span class="nav-text">鼠标与滚轮事件</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#滚轮事件"><span class="nav-number">4.3.1.</span> <span class="nav-text">滚轮事件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#客户区坐标位置"><span class="nav-number">4.3.2.</span> <span class="nav-text">客户区坐标位置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#屏幕坐标位置"><span class="nav-number">4.3.3.</span> <span class="nav-text">屏幕坐标位置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#键"><span class="nav-number">4.3.4.</span> <span class="nav-text">键</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#相关元素"><span class="nav-number">4.3.5.</span> <span class="nav-text">相关元素</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#更多事件信息"><span class="nav-number">4.4.</span> <span class="nav-text">更多事件信息</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#键盘和文件属性"><span class="nav-number">4.5.</span> <span class="nav-text">键盘和文件属性</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#键码"><span class="nav-number">4.5.1.</span> <span class="nav-text">键码</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#textInput-事件"><span class="nav-number">4.5.2.</span> <span class="nav-text">textInput 事件</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#复合事件"><span class="nav-number">4.6.</span> <span class="nav-text">复合事件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#变动事件"><span class="nav-number">4.7.</span> <span class="nav-text">变动事件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#HTML5-事件"><span class="nav-number">4.8.</span> <span class="nav-text">HTML5 事件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#设备事件"><span class="nav-number">4.9.</span> <span class="nav-text">设备事件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#触摸与手势事件"><span class="nav-number">4.10.</span> <span class="nav-text">触摸与手势事件</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#内存和性能"><span class="nav-number">5.</span> <span class="nav-text">内存和性能</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#事件委托"><span class="nav-number">5.1.</span> <span class="nav-text">事件委托</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#移除事件处理程序"><span class="nav-number">5.2.</span> <span class="nav-text">移除事件处理程序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#禁止a标签的默认行为"><span class="nav-number">5.3.</span> <span class="nav-text">禁止a标签的默认行为</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#一个判断客户端是-PC-端还是移动端的程序"><span class="nav-number">6.</span> <span class="nav-text">一个判断客户端是 PC 端还是移动端的程序</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#图片跟着鼠标飞"><span class="nav-number">7.</span> <span class="nav-text">图片跟着鼠标飞</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#模拟多人开发注册事件"><span class="nav-number">8.</span> <span class="nav-text">模拟多人开发注册事件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#注册多个事件"><span class="nav-number">9.</span> <span class="nav-text">注册多个事件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#事件冒泡阶段判断"><span class="nav-number">10.</span> <span class="nav-text">事件冒泡阶段判断</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#阻止事件冒泡"><span class="nav-number">11.</span> <span class="nav-text">阻止事件冒泡</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#有关事件处理的函数的封装"><span class="nav-number">12.</span> <span class="nav-text">有关事件处理的函数的封装</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#动画函数封装（js）"><span class="nav-number">13.</span> <span class="nav-text">动画函数封装（js）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#总结三大系列"><span class="nav-number">14.</span> <span class="nav-text">总结三大系列</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Hongqin Ma</span>
</div>

<div class="powered-by">
  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span id="busuanzi_container_site_pv">
    &nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;Page Views: <span id="busuanzi_value_site_pv"></span> 
</span>

        

<div class="busuanzi-count">

  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv"><i class="fa fa-user"></i><span class="busuanzi-value" id="busuanzi_value_site_uv"></span></span>
  

  
    <span class="site-pv"><i class="fa fa-eye"></i><span class="busuanzi-value" id="busuanzi_value_site_pv"></span></span>
  
  
</div>



        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"Hiraku"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  






  
  

  

  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  
  <!-- custom analytics part create by xiamo -->
<script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
<script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
<script>
function showTime(Counter) {
  var query = new AV.Query(Counter);
  $(".leancloud_visitors").each(function() {
    var url = $(this).attr("id").trim();
    query.equalTo("url", url);
    query.find({
      success: function(results) {
        if (results.length == 0) {
          var content = '0 ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
          return;
        }
        for (var i = 0; i < results.length; i++) {
          var object = results[i];
          var content = object.get('time') + ' ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
        }
      },
      error: function(object, error) {
        console.log("Error: " + error.code + " " + error.message);
      }
    });

  });
}

function addCount(Counter) {
  var Counter = AV.Object.extend("Counter");
  url = $(".leancloud_visitors").attr('id').trim();
  title = $(".leancloud_visitors").attr('data-flag-title').trim();
  var query = new AV.Query(Counter);
  query.equalTo("url", url);
  query.find({
    success: function(results) {
      if (results.length > 0) {
        var counter = results[0];
        counter.fetchWhenSave(true);
        counter.increment("time");
        counter.save(null, {
          success: function(counter) {
            var content =  counter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(counter, error) {
            console.log('Failed to save Visitor num, with error message: ' + error.message);
          }
        });
      } else {
        var newcounter = new Counter();
        newcounter.set("title", title);
        newcounter.set("url", url);
        newcounter.set("time", 1);
        newcounter.save(null, {
          success: function(newcounter) {
              console.log("newcounter.get('time')="+newcounter.get('time'));
            var content = newcounter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(newcounter, error) {
            console.log('Failed to create');
          }
        });
      }
    },
    error: function(error) {
      console.log('Error:' + error.code + " " + error.message);
    }
  });
}
$(function() {
  var Counter = AV.Object.extend("Counter");
  if ($('.leancloud_visitors').length == 1) {
    addCount(Counter);
  } else if ($('.post-title-link').length > 1) {
    showTime(Counter);
  }
}); 
</script>

  
</body>
</html>
